Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FB Graph API query doesn't work in PHP SDK

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?

like image 986
Chris Avatar asked Aug 01 '15 07:08

Chris


1 Answers

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.

like image 69
Adexe Rivera Avatar answered Oct 31 '22 09:10

Adexe Rivera