Facebook graph使用PHP获取帖子的喜欢/评论数
我尝试过很多方法,但都失败了 我正在使用facebook php sdk创建我自己的新闻提要(提要来自页面的时间线) 要在facebook上获得喜欢的内容,我使用$post['likes'],其中喜欢的内容将输出:Facebook graph使用PHP获取帖子的喜欢/评论数,php,facebook,facebook-graph-api,facebook-php-sdk,Php,Facebook,Facebook Graph Api,Facebook Php Sdk,我尝试过很多方法,但都失败了 我正在使用facebook php sdk创建我自己的新闻提要(提要来自页面的时间线) 要在facebook上获得喜欢的内容,我使用$post['likes'],其中喜欢的内容将输出: "data": [ { "id": "100001919135377", "name": "Person name" }, { "id
"data": [
{
"id": "100001919135377",
"name": "Person name"
},
{
"id": "1153253855",
"name": "Person name"
},
{
"id": "100000945245573",
"name": "Person name"
},
{
"id": "100002595937528",
"name": "Person name"
},
{
"id": "100001873157306",
"name": "Person name"
},
{
"id": "1356273210",
"name": "Person name"
}
]
我如何计算喜欢的数量,然后回应
对于评论也是一样,我使用$post['comments'],它会输出
"data": [
{
"id": "637555672952364_6191387",
"from": {
"name": "Person Name",
"id": "1153253855"
},
"message": "Comment content",
"can_remove": false,
"created_time": "2014-01-11T07:28:37+0000",
"like_count": 0,
"user_likes": false
},
{
"id": "637555672952364_6191388",
"from": {
"name": "Person Name",
"id": "1153253855"
},
"message": "Comment content",
"can_remove": false,
"created_time": "2014-01-11T07:28:39+0000",
"like_count": 0,
"user_likes": false
}
]
同样的事情,我想数一数评论的数量,并回应它
如果你需要知道更多的信息,请告诉我
提前感谢使用count()
函数获取JSON
数组的元素数
下面是一个简单的PHP
示例,其中包含file\u get\u内容
<?php
function fetchUrl($url){
return file_get_contents($url);
}
$authToken = "{Token}";
$json_object = fetchUrl("https://graph.facebook.com/{POST_ID}/likes?$authToken}&limit=5000"); //
$feedarray = json_decode($json_object, true);
$likesNum = count($feedarray['data']); // return the number of items in `data` array
print $likesNum;
?>
同样的事情也适用于注释使用count()
函数获取JSON
数组的元素数
下面是一个简单的PHP
示例,其中包含file\u get\u内容
<?php
function fetchUrl($url){
return file_get_contents($url);
}
$authToken = "{Token}";
$json_object = fetchUrl("https://graph.facebook.com/{POST_ID}/likes?$authToken}&limit=5000"); //
$feedarray = json_decode($json_object, true);
$likesNum = count($feedarray['data']); // return the number of items in `data` array
print $likesNum;
?>
同样的方法也适用于注释尝试在api调用中使用comments.summary(true)
例如,尝试在api调用中使用comments.summary(true)
这里有一个简单的方法,可以从Facebook上获得类似Facebook的计数
<?php
function fetchUrl($url) {
return file_get_contents($url);
}
$authToken = "{token}"; // Authentication Token
$facebookUrl = "{page name only}"; // https://www.facebook.com/page name
$json_object = fetchUrl("https://graph.facebook.com/$facebookUrl/?fields=fan_count&access_token=$authToken");
$feedarray = json_decode($json_object, true);
echo number_format($feedarray['fan_count'],0,",","' "); // Will display count : 00'000
echo $feedarray['fan_count']; // Will display count : 00000
?>
这里有一个简单的方法,可以从Facebook获得类似Facebook的计数
<?php
function fetchUrl($url) {
return file_get_contents($url);
}
$authToken = "{token}"; // Authentication Token
$facebookUrl = "{page name only}"; // https://www.facebook.com/page name
$json_object = fetchUrl("https://graph.facebook.com/$facebookUrl/?fields=fan_count&access_token=$authToken");
$feedarray = json_decode($json_object, true);
echo number_format($feedarray['fan_count'],0,",","' "); // Will display count : 00'000
echo $feedarray['fan_count']; // Will display count : 00000
?>
您可以使用此
$json_object = fetchUrl("https://graph.facebook.com/{POST_ID}/likes?field=total_count");
你可以用这个
$json_object = fetchUrl("https://graph.facebook.com/{POST_ID}/likes?field=total_count");
您的数据是json格式的,您是否尝试使用json_解码(“json字符串”,true);这将给你一个数组,你可以使用一些数组操作来获得计数。我是一个真正的PHP初学者,不知道怎么做。。。我所知道的是我应该计算对象的数量,其中一个对象是{“id”:“100002595937528”,“name”:“Person name”}你能发布你的代码和所需的输出吗?我的提要有它的代码,但我目前根本没有我在这里要求的代码,这就是为什么我要问这个问题:P我只想回应一下评论和喜欢的数量。为了得到这个json数据,我要么做$post['comments']要么做$post['likes'],这是我的完整代码,我想在comment//TEST-LIKE-count中添加post计数。如果您的数据是json格式的,您是否尝试使用json_解码(“json字符串”,true);这将给你一个数组,你可以使用一些数组操作来获得计数。我是一个真正的PHP初学者,不知道怎么做。。。我所知道的是我应该计算对象的数量,其中一个对象是{“id”:“100002595937528”,“name”:“Person name”}你能发布你的代码和所需的输出吗?我的提要有它的代码,但我目前根本没有我在这里要求的代码,这就是为什么我要问这个问题:P我只想回应一下评论和喜欢的数量。为了获得这个json数据,我要么执行$post['comments']要么执行$post['likes'],这是我的完整代码,我想在注释//测试类计数的位置添加post计数