How does one retrieve the fan_count for a Facebook application page using the Graph API?

只愿长相守 提交于 2019-12-02 18:38:07

问题


I need to retrieve the number of fans for a given Facebook application. Using the GraffitiWall application example in the Facebook Graph API, that page displays a fan total numbering somewhere near 1.2 million. The Graph API, however, returns no fan_count:

{
 "id": "2439131959",
 "name": "Graffiti",
 "description": "Graffiti lets you draw on your friends' profiles.",
 "category": "Just For Fun",
 "link": "http://www.facebook.com/graffitiwall"
}

Are the likes on the graffitiwall application likes for the page or for the application? If for the page, how do I programmatically determine the page ID given the application ID? If for the application, how do I get that fan count? Do I need to be an admin for that application? Is this only available using Facebook Insights?

For the record, I've also tried specifying the application ID, but that also returns the above block. Using the application page URL, a shares value is returned:

{
 "id": "http://www.facebook.com/graffitiwall",
 "shares": 19
}

Perhaps I'm missing something in the API documentation or the Graph API forum, but I couldn't find the answer in either location.


回答1:


You can get number of fans by running FQL on page table:

FB.Data.query("select fan_count from page where page_id = 2439131959");

(fan_count is undocumented field btw, either it is deprecated or they just forgot to mention it in their docs which wouldn't surprise me much)

Not sure if you were asking about likes as well, but just in case here is an example how to get number of likes by url:

FB.Data.query('select like_count from link_stat where url="http://www.facebook.com/graffitiwall"');



回答2:


You can also get fan_count using the REST API:

% wget https://api.facebook.com/method/pages.getinfo?access_token=[...]&fields=fan_count,name&page_ids=2439131959&format=json
[{"page_id":2439131959,"name":"Graffiti","fan_count":1263811}]

as described in the Facebook Developer wiki.



来源:https://stackoverflow.com/questions/3231099/how-does-one-retrieve-the-fan-count-for-a-facebook-application-page-using-the-gr

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!