0

I have a simple PHP code that fetches Facebook graph API's value (total number of likes of a certain fanpage) via JSON. It works perfectly fine for the vast majority of fan pages but for 3 (out of 17 fan pages that I track) it simply can't read and print that value.

I don't understand where's the problem since the data I want to fetch is publicly available and the same code is applied for all pages.

Here's the code that prints correct value for a fan page with ID 214014840762:

<?php    
$currsiteurl = 'http://graph.facebook.com/214014840762';  
$graph = json_decode(file_get_contents($currsiteurl));  
$currnofans = $graph->likes;  
echo "Number of likes: ".$currnofans; // prints out 107936    
?>

But if I simply change the ID to 160788560626000 or 167134649991034 the same code doesn't work anymore and it doesn't print anything.

Thanks in advance!

1
  • 1
    maybe a privacy setting of the page? Commented May 1, 2011 at 22:31

2 Answers 2

2

I don't know what these pages are or what their URLs on Facebook are, so I can't verify this but, it's possible that your page is either not published (probably not that likely), or (probably more likely) is age restricted. The Facebook graph doesn't let you access a page's information if it is restricted by age. Unfortunately, this is even true if you pass a Facebook application access token, or even an access token for a user who is over 18. It's pretty stupid, and there have got to be at least 5 bug reports on bugs.developers.facebook.com for it.

Update 6/13/2011
Recently, Facebook made an update that requires you to use a valid user access token to pull information about a page. This is a horrendous change, imo, but it is what it is. Without a valid user access token, you will get a false or error response from every endpoint that isn't the basic info (root, http://graph.facebook.com/<page_id>) or photos, or albums endpoints.

So, if you're requested any of the other endpoints (posts, feed, videos, statuses, etc) you'll need to make sure you provide a valid user access token to access them.

Sign up to request clarification or add additional context in comments.

Comments

-1

If I'm right then is the result an array and not a class so try something like $graph["likes"]

1 Comment

considering that it works for the other pages that are structured in the same way, I don't see how that could be the case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.