I am trying to get a users friends count from Facebook php sdk v5. How can I parse the response from as a php array or how can I retrieve the total friends count? ->asArray() (that i use with getGraphUser) does not work on getGraphEdge it seems. I am unsure how to access or convert it.
try {
// Returns a `Facebook\FacebookResponse` object
$response = $cfb->get('/me/friends?fields=id', $_SESSION['fb_token']);
$friends = $response->getGraphEdge();
} catch(Facebook\Exceptions\FacebookResponseException $e) {
echo 'Graph returned an error: ' . $e->getMessage();
//exit;
} catch(Facebook\Exceptions\FacebookSDKException $e) {
echo 'Facebook SDK returned an error: ' . $e->getMessage();
//exit;
}
Facebook\GraphNodes\GraphEdge Object
(
[request:protected] => Facebook\FacebookRequest Object
(
[app:protected] => Facebook\FacebookApp Object
(
[id:protected] => ****
[secret:protected] => ****
)
[accessToken:protected] => *****
[method:protected] => GET
[endpoint:protected] => /me/friends?fields=id
[headers:protected] => Array
(
[Content-Type] => application/x-www-form-urlencoded
)
[params:protected] => Array
(
)
[files:protected] => Array
(
)
[eTag:protected] =>
[graphVersion:protected] => v2.2
)
[metaData:protected] => Array
(
[summary] => Array
(
[total_count] => 468
)
)
[parentEdgeEndpoint:protected] =>
[subclassName:protected] =>
[items:protected] => Array
(
)
)
Thanks in advance!
Had to use the getTotalCount() method.
https://developers.facebook.com/docs/php/GraphEdge/5.0.0#get-total-count