开发者

facebook graph api determine if user likes url

I want to display a different message if a user is currently logged in to facebook and likes the current page. I understand:

FB.Event.subscribe('edge.create', function(respo开发者_运维知识库nse) {
    // you like this
});

Which will fire when a user likes the page, but when you reload the page how do you determine they already like the current page?

Thanks!


I'm pretty sure you cant do what you want (in this context).

Take a look at this page : http://fbrell.com/fb.api/does-like

You'll see you need the user to approve a permission to view the likes.

It's a huge security risk to allow someone to see the 'likes' of a user - even for the current page. Think about it you can easily spoof the current page and pretend to be any page.

BUT...

What I recommend you do is just set a cookie for your own benefit (in javascript) when the user 'Likes' your page. Assuming you're getting a large percentage of your 'Likes' from this page then you can safely correlate the presence of the cookie with a 'Like'.

I've seen some security exceptions doing this, but it seems to work (at least in Chrome).


Sense you describe the page as "current page" I understand that it is in an iframe tab. If this is the case, signed request supplies you with that information as $decode_signed_request = array('page' => array('liked' => true/false)).

Otherwise you can supply a canvas page with the GET parameters fb_page_id, which should include the parameter fb_sig_added to the server request with a 0/1 depending on if the user is a fan of that page. (This may require disabling OAuth 2.0 in your migration settings)

If you are talking about the like social plugin with an open graph url, you can not readily find out if the user is a fan without an application installation. If you do have that you can do an api call to /me/likes which will return a list of all the likes that user has, and search for the id of the object you are testing for.


You're safer using the Graph API since Facebook is in the process of deprecating their REST API. So to get if a user likes your page, you will need the page ID and the access token of your app.

https://graph.facebook.com/me/likes/PAGE_ID?format=json&access_token=ACCESS_TOKEN

  • Where PAGE_ID is the page id you want to check.
  • and ACCESS_TOKEN is your apps access token.


From the Graph API you can get the likes of a user by his id, as:

https://graph.facebook.com/ID/CONNECTION_TYPE

so for getting the likes you put your access token and:

https://graph.facebook.com/me/likes?access_token=2222222222222222

then look for your page if it is liked or not.

However you can always try FQL queries which i didnt try for Likes actually.

I hope that helped.


save user id or third_party_id in database when the user liked the link

to Get third_party_id

graph.facebook.com/me/?fields=third_party_id&access_token=xxx


https://graph.facebook.com/{FB_USER_ID}?fields=likes.target_id(167584559969748)&access_token={VALID_ACCESS_TOKEN}

shows data if that user has liked that Facebook fan page.

or

https://graph.facebook.com/{FB_USER_ID}?fields=likes.fields(link)

shows a list of liked links, from where you can get the link you are looking for.

All of these need 'user_likes' and/or friend_likes permissions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜