【发布时间】:2015-09-04 06:04:31
【问题描述】:
我正在开发一个需要 Facebook 集成的 PHP 项目。因此,在我对代码执行此操作之前,我正在使用 Facebook Graph API 资源管理器工具 (https://developers.facebook.com/tools/explorer) 对其进行测试。我现在正在做的是。
第一步
Get the user access_token by using the button at the top left.
第二步
Make a GET request to "me/accounts" to get the page token and page id.
第三步
Make a POST request to "{page_id}/feed" with the fields message={message} and access_token={page_token}
它运行良好并发布在我的 Facebook 粉丝页面上。但是当我尝试用这样的 PHP 代码替换“第三步”时
$data['message'] = "my message";
$data['access_token'] = $page_access_token; //page token from 2nd step
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, 'https://graph.facebook.com/{page_id}/feed');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch,CURLOPT_POSTFIELDS, $data);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_POST, 1);
$resp = curl_exec($ch);
curl_close($ch);
$data_resp = json_decode($resp);
print_r($data_resp);
它显示了这个错误。
stdClass Object ( [error] => stdClass Object ( [message] => (#200) Permissions error [type] => OAuthException [code] => 200 ) )
我设置了manage_pages、publish_pages、publish_actions的权限
【问题讨论】:
-
调试您的
access_token并检查它是否获得了所需的权限。 developers.facebook.com/tools/debug
标签: php facebook facebook-graph-api curl