How to get Facebook likes count for a Facebook pag

2019-03-31 12:46发布

问题:

I am making GET request to Facebook graph API like:

https://graph.facebook.com/Yahoo?fields=likes

It is returning the likes count even if I am not logged in.

But for URLs like: https://graph.facebook.com/CaraSutrasPage?fields=likes

I am NOT getting the Facebook likes when I am not logged-in. The reason here is, this Facebook page is age-restricted.

From this question, I tried including the User access_token like: https://graph.facebook.com/CaraSutrasPage?fields=likes&access_token=CAAGRLGYz...User_access_token

But this works only when that user is logged into developer.facebook.com site. After logged-out it is returning "Error validating access token: This may be because the user logged out or may be due to a system error." message.

I want to get the Facebook likes for a list of Facebook page URLs(e.g. https://www.facebook.com/TheRedheadBedhead and https://www.facebook.com/pages/Sexational/382577001850507?ref=hl) which are stored in database. I have not idea about which are age-restricted and which are not!

Is there any way if I can get the likes count using FQL?

I am looking for a way to get the facebook likes by any method: GET request(e.g. https://graph.facebook.com/CaraSutrasPage?fields=likes), POST request or FQL!

Any help is highly appreciated!

回答1:

You can simply hit the url and pass your pageId and token

 https://graph.facebook.com/<YOUR_PAGE_NAME>/?fields=fan_count&access_token=<YOUR_ACCESS_TOKEN>

It will return a Json object.