简体   繁体   English

如何在Facebook的SDK中使用图形api访问令牌在php中

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

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 然后我得到一个带有两个键的数组: datapaging

Inside of data I get an array of the pages I own, where the access_token is available for each page. data内部,我得到了我拥有的页面的数组,其中每个页面都可以使用access_token。

According to this page: 根据此页面:

https://developers.facebook.com/docs/graph-api/reference/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: 消息引发FacebookApiException:

(#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! 谢谢!

Can you try 你能试一下吗

$access_token = $facebook->getAccessToken();

And before calling the API do something like 在调用API之前,请执行以下操作

$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. 但是,正如Shankar Damodaran回答的那样,您也可以检查他的脚步。

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 另外,您还可以尝试从个人资料中删除该APP,并尝试进行连接并重试授予权限,看看是否可以解决问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM