Chris
Chris

Reputation: 1317

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?

Upvotes: 5

Views: 7523

Answers (2)

yedort
yedort

Reputation: 1

Newer PHP SDK versions have the getGraphList() method, getGraphEdge() is for the earlier, even though it wasn't documented.

Upvotes: 0

Adexe Rivera
Adexe Rivera

Reputation: 422

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.

Upvotes: 7

Related Questions