how to use graph api access token in php for facebook sdk

六月ゝ 毕业季﹏ 提交于 2019-12-12 01:34:42

问题


I'm really stuck on this matter.

I've been reading the documentation over and over and I don't understand how to use the access token for my page, so that I could pull the page's messages.

This is my code:

$user_id = $facebook->getUser();
if($user_id) {
    $user_profile = $facebook->api('/me/accounts', 'GET');
}

and then I get an array, with two keys: data and paging

Inside of data I get an array of the pages I own, where the access_token is available for each page.

According to this page:

https://developers.facebook.com/docs/graph-api/reference/page

I should be able to access my page's inbox by calling the edge:

/{page_id}/conversations

but when I do it this way:

$facebook->api($page_id.'/conversations', 'GET');

The FacebookApiException is thrown with the message:

(#10) Application does not have permission for this action

but I'm sure I've permission for that action. I'm sure it has something to do with the access token, but I just don't know what to do with it.

What am I missing? How do I use my page's access token to read my inbox?

Thanks!


回答1:


Can you try

$access_token = $facebook->getAccessToken();

And before calling the API do something like

$facebook->setAccessToken($new_access_token);
$facebook->api($page_id.'/conversations', 'GET');

The above should solve the access token issue. However as replied by Shankar Damodaran you may check his steps as well.

Also In addition you can try to remove the APP from your profile and try to do a connect and retry giving permissions and see if this resolves the issue



来源:https://stackoverflow.com/questions/20918712/how-to-use-graph-api-access-token-in-php-for-facebook-sdk

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!