我是PHP和Facebook PHP SDK的新手,我希望'like_count'从'likes' 'summary'Facebook页面帖子中获取.我当前的代码包含以下内容:
$response = $fb->get('/me/posts?fields=admin_creator,likes.limit(0).summary(true)&limit=30');
$getLikeCount = $response->getGraphEdge()->asArray();
foreach($getLikeCount as $likekey){
if(isset($likekey['likes'])){
var_export($likekey['likes']);
foreach ($likekey['likes'] as $likekey){
//echo $likekey['total_count'] . '<br>';
}
}
}
Run Code Online (Sandbox Code Playgroud)
该var_export($likekey['likes']);出口空白阵列,同时var_export($likekey['summary']);返回null.但是,在Graph API Explorer中,它返回以下内容:
{
"admin_creator": {
"name": "NAME",
"id": "ID"
},
"id": "ID",
"likes": {
"data": [
],
"summary": {
"total_count": 1022,
"can_like": true,
"has_liked": false
}
}
},
Run Code Online (Sandbox Code Playgroud)
我如何访问该'total_count'字段,因为通过我的方法访问它'likes'并且" summary'不工作".
编辑:使用getGraphEdge()->asArray();将无法工作,因为它不返回摘要数组.我会以某种方式获取值getDecodedBody();或其他方法.如果我使用$getLikeCount = $response->getDecodedBody();,使用此代码: …