Facebook Graph API - likes returns me an empty set
When I try to get all my "likes" (formerly fan pages) on Facebook Graph API, sometimes it returns me an empty set:
{
"data": [
]
}
I tried with https://graph.facebook.com/me/likes?access_token=MY_ACCESS_TOKEN and with graph.facebook.com/vinch/likes?a开发者_StackOverflowccess_token=MY_ACCESS_TOKEN but the result is exactly the same (empty).
Any idea of what it can be? I need it to know if a user likes (is fan of) a specific page.
add user_likes permission to your application
I read in the Changelog of 2010-12-12:
GET [page-id]/members/[user-id] will return the individual user if he or she is a fan of the page (Graph API equivalent of pages.isFan) (rE322057)
So, you can check with Graph API if a known user_id is fan of a known page_id with exactly this syntax. You need to supply a valid access_token. With the fields parameter you can choose, what the API should return. E.g. append "&fields=id,name,picture" to get the id, name and picture in case the user is a fan.
{
"data": [
{
"id": "712084216",
"name": "Mike Bretz",
"picture": "http://profile.ak.fbcdn.net/hprofile-ak-snc4/hs842.snc4/70441_712084216_5491098_q.jpg"
}
]
}
You'll get an empty result if the user is not a fan
{
"data": [
]
}
If you are using Graph API Explorer. you can set permissions by taking get Access Token Button on the Top and specify user_likes and click ok.. Try your code again..
Hope this helps
Yesterday facebook fixed likes (http://developers.facebook.com/live_status#msg_612)
You can get only user likes not object likes. For example, you can not get all users by page_id.
If all you need to know is whether or not a user is a fan of something (and not a list of likes or a list of fans) this should do the trick: http://developers.facebook.com/docs/reference/rest/pages.isFan.
You can't get the likes of a fan page through the API. Follow this bug for more info: http://bugs.developers.facebook.net/show_bug.cgi?id=12880
My test user had approved my app before the likes permission had been granted so it was never picking up the likes authorisation. By removing the app from the test user's profile and authorising again I was able to get their likes.
You cannot get likes
of a post
because of permission concern problem.
https://developers.facebook.com/docs/graph-api/reference/v4.0/object/likes#readperms
精彩评论