我需要与Facebook分享图片。为此,我正在尝试建议here的API调用
FB.login(function(response) {
if (response.authResponse) {
FB.api(
"/{page-id}/photos",
"POST",
{
"url": "https:\/\/www.facebook.com\/images\/fb_icon_325x325.png",
"published": "false"
},
function (response) {
if (response && !response.error) {
console.log(JSON.stringify(response))
/* handle the result */
}
else
{
console.log("ERROR: " + JSON.stringify(response))
}
}
);
} else {
console.log('User cancelled login or did not fully authorize.');
}
});
但我收到错误(#803) Some of the aliases you requested do not exist: {page-id}
页面ID与authResponse中返回的userID相同吗?因为我也试过硬编码那个id,但是我得到了一个弃用的API消息。
我需要允许用户将照片直接分享到他的Feed中。
谢谢
页面ID和用户ID不一样。您在获得授权后获得用户ID,您将使用带有用户令牌的/me/accounts
端点获取页面ID。您还可以使用/me/accounts?fields=access_token
获取Page Tokens。您需要使用具有publish_pages和manage_pages权限的页面令牌在您管理的页面上创建帖子或照片。
正如WizKid评论的那样,您也可以使用/me/photos
上传照片。只需使用页面令牌。
更多信息:https://developers.facebook.com/docs/facebook-login/access-tokens/