我试图从Facebook php sdk v5获得用户朋友数。如何解析来自php数组的响应或如何检索总朋友数? - > asArray()(我使用getGraphUser)似乎对getGraphEdge不起作用。我不确定如何访问或转换它。
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
(
)
)
提前致谢!
答案 0 :(得分:3)
必须使用getTotalCount()方法。
https://developers.facebook.com/docs/php/GraphEdge/5.0.0#get-total-count