0

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

?>
Cœur
  • 37,241
  • 25
  • 195
  • 267
James
  • 17
  • 6

2 Answers2

1

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.

andyrandy
  • 72,880
  • 8
  • 113
  • 130
0

The Facebook API has changed .

  • The fan_count can be retrieved using an user token only after aprovement by Facebook Platform, completing the submission process .
  • The fan_count can be retrieved using page access tokens, to get fan count for that page .

Attention: Graph Explorer can get the page information if yours pages, so, be carefull on testing your apps, and use TEST USERS for testing insead your profile, ok ,

After test submit it for aprooval, and you be done !

David Augustus
  • 420
  • 3
  • 9