FB Graph API query doesn't work in PHP SDK

怎甘沉沦 提交于 2019-12-07 06:56:38

问题


Graph API: 2.4
PHP SDK: "facebook/php-sdk-v4": "~5.0"

I'd like to get details about a page via PHP and the PHP SDK. Using the query:

$response = $fb->get('/' . $sPageID . '?fields=posts', $_SESSION['facebook_access_token']);

returns the posts with a good amount of data. But unfortunately wrong values:
The limit 25 for likes for instance applies here. So even if one post should have 150 likes, if I do an count ($post['likes']) I only get 25 as a result.

So I tried to change my query and according to the Graph Explorer this seems to be working fine: PAGE_ID/posts?fields=likes.limit(100),message,comments,shares,picture,link,type

Now I can't get this transformed into my PHP call. I receive timeouts and

Fatal error: Uncaught exception 'Facebook\Exceptions\FacebookSDKException' with message 'Unable to convert response from Graph to a GraphNode because the response looks like a GraphEdge. Try using GraphNodeFactory::makeGraphEdge() instead.' in ...

Is this possible with one query in PHP or do I have to run multiple queries, one for each post?


回答1:


I found this answer, and if because the end of point of this request is a GraphEdge, so try this:

// Get basic info on the user from Facebook.
try {
    $response = $fb->get('/' . $sPageID . '?fields=posts', $_SESSION['facebook_access_token']);

} catch (Facebook\Exceptions\FacebookSDKException $e) {
    dd($e->getMessage());
}
$getGraphEdge = $response->getGraphEdge();

I hope this help you.

Regards.




回答2:


Use getGraphList(), if you have problems with getGraphEdge().



来源:https://stackoverflow.com/questions/31759593/fb-graph-api-query-doesnt-work-in-php-sdk

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