我正在尝试使用新的facebook sdk(V 5.0)从我的facebook页面获取帖子的反应数量 但是当我执行请求时,它向我返回了一个空数组作为反应键 但是,当我在Graph facebook Explorer上执行相同的请求时,它起作用了,它向我返回了每个帖子的反应摘要
这是我的代码:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
$fb = new Facebook([
'app_id' => '1795766XXX',
'app_secret' => 'e6b0d137adf110e089d9eeXXXX',
'default_graph_version' => 'v3.2',
'default_access_token' => 'EAACjUvPz1UUBAFMlFb5CQzsRx0jYUCZCIIYddqUtyXXX',
]);
$data = $fb->get('/252613XX/posts?fields=id,reactions.type(LOVE).limit(0).summary(total_count)');
$posts = $data->getGraphEdge();
echo '<pre>';
var_dump($posts->asArray());
echo '</pre>';
输出:
array(25) {
[0]=>
array(2) {
["id"]=>
string(30) "252613xxxx_101568062385xxxx"
["reactions"]=>
array(0) {
}
}
[1]=>
array(2) {
["id"]=>
string(30) "25261330xxx_1015680576642xxxx"
["reactions"]=>
array(0) {
}
}
[2]=>
array(2) {
["id"]=>
string(30) "25261330xxx_1015680568030xxx"
["reactions"]=>
array(0) {
}
}
[3]=>
array(2) {
["id"]=>
string(30) "2526133xxx_1015680571755xxx"
["reactions"]=>
array(0) {
}
}
[4]=>
array(2) {
["id"]=>
string(30) "2526133xxx_101568058112xxx"
["reactions"]=>
array(0) {
}
}
我不知道如何解决我的问题
更新代码:
ini_set('display_errors', 'On');
error_reporting(E_ALL);
require_once('vendor/autoload.php');
use Facebook\Facebook;
use Facebook\FacebookApp;
use Facebook\FacebookRequest;
$fb = new Facebook([
'app_id' => 'XXXX',
'app_secret' => 'XXXX',
'default_graph_version' => 'v3.2',
'default_access_token' => 'xxx',
]);
$data = $fb->get('/XXX/posts?fields=id,reactions.limit(0).summary(total_count)&since=1548603879&until=1553701479&limit=100');
$posts = $data->getGraphObject();
//$posts = $data->getDecodedBody();
$all_posts = array();
$all_post_info = array();
if($fb->next($posts)){
$posts_array = $posts->asArray();
$all_posts = array_merge($posts_array, $all_posts);
while($posts = $fb->next($posts)){
echo '<pre>';
var_dump($posts);
echo '</pre>';
die();
}
}