我正在尝试使用以下代码获取用户的粉丝页面帖子,但它会给我警告
Warning: file_get_contents(https://graph.facebook.com/782176371798916/posts): failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request
$page_posts = file_get_contents('https://graph.facebook.com/'.$page_id.'/posts');
$pageposts = json_decode($page_posts);
foreach ($pageposts["data"] as $fppost) {
echo $fppost['message'];
}
那么,获取用户粉丝页面的正确方法是什么?
答案 0 :(得分:0)
我找到的解决方案是使用以下代码:
$pageposts = $facebook->api('/'.$page_id.'/posts', 'GET');
foreach ($pageposts["data"] as $fppost) {
echo $fppost['message'];
}
答案 1 :(得分:0)
您没有发送access_token
参数,只需添加它,它应该像魅力一样工作:
$page_id = 'smashmag'; // Page ID or username
$token = '553435274702353|OaJc7d2WCoDv83AaR4JchNA_Jgw'; // Valid access token, I used app token here but you might want to use a user token .. up to you
$page_posts = file_get_contents('https://graph.facebook.com/'.$page_id.'/posts?fields=message&access_token='.$token); // > fields=message < since you want to get only 'message' property (make your call faster in milliseconds) you can remove it
$pageposts = json_decode($page_posts);
foreach ($pageposts->data as $fppost) {
if (property_exists($fppost, 'message')) { // Some posts doesn't have message property (like photos set posts), errors-free ;)
print $fppost->message.'</br>';
}
}