Facebook graph api determines if user likes url

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

FB.Event.subscribe('edge.create', function(response) { // you like this }); 

What will work when the user likes the page, but when you reload the page, how do you determine if it already looks like the current page?

Thanks!

+6
javascript php facebook facebook-graph-api
source share
6 answers

I am sure that you cannot do what you want (in this context).

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

You will see that the user must approve permission to view such.

This is a huge security risk, allowing someone to see the "liked" user - even for the current page. Think about it, you can easily fool the current page and pretend to be any page.

BUT...

I recommend that you simply set a cookie for your own benefit (in javascript) when the user "likes" your page. Assuming you get a large percentage of your Likes from this page, you can safely match the presence of the cookie with Like.

I saw some security exceptions that do this, but it seems to work (at least in Chrome).

+3
source share

The meaning is that you describe the page as the "current page". I understand that it is on the iframe tab. If so, the signed request provides you this information like $decode_signed_request = array('page' => array('liked' => true/false)) .

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

If you are talking about a similar social plug-in with an open schedule, you cannot easily find out if a user is a fan without installing the application. If you have one, you can make an api call /me/likes , which will return a list of all the ones you like and will look for the identifier of the object you are testing.

+2
source share

It's safer to use the Graph API, as Facebook is in the process of deprecating the REST API. To get if the user likes your page, you need the page ID and access token of your application.

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

  • Where PAGE_ID is the identifier of the page you want to check.
  • and ACCESS_TOKEN is the application access token.
+1
source share

In the Graph API, you can get the username by its identifier, for example:

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

so to get what you like, you put your access token and:

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

then find your page if you like it or not.

However, you can always try FQL queries that I have not tried for Likes in fact.

I hope this helps.

0
source share

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

Get third_party_id

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

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

shows data if the user liked this Facebook fan page.

or

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

shows a list of favorite links, from where you can get the link you need.

All of them need user_likes and / or friend_likes .

0
source share

All Articles