facebook graph api determine if user likes url

后端 未结 6 1303
-上瘾入骨i
-上瘾入骨i 2021-02-09 17:20

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\'         


        
相关标签:
6条回答
  • 2021-02-09 17:51

    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

    0 讨论(0)
  • 2021-02-09 17:52
    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 讨论(0)
  • 2021-02-09 17:56

    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.

    0 讨论(0)
  • 2021-02-09 17:58

    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.

    0 讨论(0)
  • 2021-02-09 18:04

    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).

    0 讨论(0)
  • 2021-02-09 18:04

    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.
    0 讨论(0)
提交回复
热议问题