嗨,我需要在 Facebook 粉丝页面上发布消息
这是我的代码 当我运行此代码时出现以下错误 (#200) 用户未授权应用程序执行此操作 如果 access_token token 问题? 我如何创建 access_token
<?php
require 'facebook-php-sdk-master//src/facebook.php';
$appId = '1617691071796143';
$secret = 'd84420ccfe2fa7eecac50ca96936bb21';
$returnurl = 'lankabird.com';
$permissions = 'manage_pages, publish_stream, offline_access,read_stream';
$fb = new Facebook(array('appId'=>$appId, 'secret'=>$secret));
$fbuser = $fb->getUser();
if($fbuser){
$page_id = "1596941017191630";
$page_access_token = "";
//$page_access_token = "1617691071796143|d84420ccfe2fa7eecac50ca96936bb21";
$result = $fb->api("/me/accounts");
// loop trough all your pages and find the right one
if( !empty($result['data']) )
{
foreach($result["data"] as $page)
{
if($page["id"] == $page_id)
{
$page_access_token = $page["access_token"];
break;
}
}
}
else
{
echo "AN ERROR OCCURED: could not get the access_token. Please verify the page ID ".$page_id." exists.";
}
$fb->setAccessToken($page_access_token);
// Now try to post on page's wall
try{
$message = array(
'message' => "YOUR MESSAGE",
);
$result = $fb->api('/'.$page_id.'/feed','POST',$message);
if($result)
{
echo 'Successfully posted to Facebook Wall...';
}
}catch(FacebookApiException $e){
echo $e->getMessage();
}
}else{
$fbloginurl = $fb->getLoginUrl(array('redirect-uri'=>$returnurl, 'scope'=>$permissions));
echo '<a href="'.$fbloginurl.'">Login with Facebook</a>';
}
?>
最佳答案
publish_stream
和 offline_access
多年来一直被弃用,你们在哪里继续复制代码?您需要 publish_actions
(在您的情况下当然还有 manage_pages
)才能张贴在墙上,您可以在文档中阅读:https://developers.facebook.com/docs/graph-api/reference/v2.2/page/feed#publish
此外,请记住,如果您想公开您的应用程序,您需要使用这些权限完成审核过程:https://developers.facebook.com/docs/apps/review/login
关于read_stream
权限:
This permission is granted to apps building a Facebook-branded client on platforms where Facebook is not already available. For example, Android and iOS apps will not be approved for this permission. In addition, Web, Desktop, in-car and TV apps will not be granted this permission.
来源:https://developers.facebook.com/docs/facebook-login/permissions/v2.2#reference-read_stream
...意思是,您不会获得 read_stream
批准。
编辑:如果您想“作为页面”发布内容,您现在也可以使用权限 publish_pages
。有关详细信息,请参阅更改日志:https://developers.facebook.com/docs/apps/changelog#v2_3_changes
关于php - 用户未授权应用程序执行此操作(#200),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28208192/