douchensi8625 2018-04-12 09:36
浏览 41

Facebook API变化? PHP获取页数错误

Facebook API Broken?

Ive got this code ive been using for a while now that looks at a facebook page and reports back how many fans the page has. However over the past few days its stopped working and im now getting the following error. Can anyone shed any light on why this is happening?

Error:

Warning: file_get_contents(https://graph.facebook.com/themeparkguide?access_token=2007*********3|9b5***********fcd&fields=fan_count): failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden in /homepages/28/d541****/htdocs/*********project/facebook_stats.php on line 4
0

Code:

<?php
function fbLikeCount($id,$appid,$appsecret){
  $json_url ='https://graph.facebook.com/'.$id.'?access_token='.$appid.'|'.$appsecret.'&fields=fan_count';
  $json = file_get_contents($json_url);
  $json_output = json_decode($json);
  //Extract the likes count from the JSON object
  if($json_output->fan_count){
    return $fan_count = $json_output->fan_count;
  }else{
    return 0;
  }
}
echo fbLikeCount('coregenie','___APPID___','___APPSECRET___');

//https://stackoverflow.com/questions/37572559/facebook-graph-api-read-followers-count/42336057

?>
  • 写回答

2条回答 默认 最新

  • doujilou3903 2018-04-12 10:43
    关注

    It works in the API Explorer: https://developers.facebook.com/tools/explorer/?method=GET&path=themeparkguide%3Ffields%3Dfan_count&version=v2.12

    So i assume with some error logging, you would get the error that your App is inactive. Try with a different or new App instead. This should not be affected by the recent changes.

    Side note: You should not use that script on every page load, better cache the result for some time. If a lot of users visit the page in a short time, you will hit the rate limit.

    评论

报告相同问题?

悬赏问题

  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置