Is it possible for canvas to check if user has liked a certain page without requesting user_likes extended permission? I have the page_id I need to check against.
I know it's entirely possible in a page tab as the check is made against the page user is currently browsing, but what about canvas? I'd really hate to ask for extended permissions just for this check.
The answer is: no, there is no way for canvas to check if user has liked a certain page without requesting permissions.
You can read the page_fan table, using fql. But you do need permission.
A Facebook user who likes a Page as represented in FQL.
The User object has an equivalent likes connection.
To read the page_fan table you need
any valid access_token if it is public (visible to anyone on Facebook).
user_likes permissions if querying the current user.
friends_likes permissions if querying a user's friend.
The above paragraph from this Facebook doc page clearly states that you need the user_likes permission. Check out the link to see what info the tables contain.
If you have the user_likes permission (or if the user has public likes) the quickest way to check if a user likes a particular page is a call to /USER_ID/likes/PAGE_ID with that user's access token
I imagine most users' privacy will be set such that you need the user_likes permission though
Here is a little trick, how you could solve this and we used it before. I know this is not a really clean and nice solution, but it works.
You need to create a session to save a boolean variable called $is_fan in it. On your canvas page you check if this param is available. On init it is not available so you redirect to your fanpage using the app_data param to pass, that the $is_fan has to be checked. On your fanpage you can check then if the user is fan and save it to the session. Then redirect to the canvas page.
in my browser the two redirects take about 1-2 seconds, which was ok for me...
Not an nice solution, but it works....
Related
I am trying to use facebook graph api to find out if a user has liked a particular page.This is the query I tried
https://graph.facebook.com/user_id/likes/page_id?access_token="my access token"
I tried the same kind of query to find if two users are friends but its returning empty data set even for that.
https://graph.facebook.com/user_id/frineds/user_id
How should I solve that issue?
You can use
GET /v2.2/{user-id}/likes/{page-id}
to find out if a user likes a page. Remember that you need the user_likes permission!
See
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/likes#readmodifiers
For seeing if a user is a friend of another user, try
GET /v2.2/{user-id-a}/friends/{user-id-b}
You need the user_friends permission to do so.
https://developers.facebook.com/docs/graph-api/reference/v2.2/user/friends#readmodifiers
When a user lands on my website I would like to present him with a litebox with the like facebook widget in it. However I only want to do this if they haven't already liked our facebook page.
I want to make this process seamless so I dont want to have to ask for permission first.
I read somewhere that if its for your own sites FB page, then you dont require this.
But cant find any more information other than a person stating this in the stackoverflow.
Any help much appreciated.
thanks
andy
You would need to go through the review process with the user_likes permission. Facebook will not approved user_likes for that, because like gating is not allowed anymore.
It was possible earlier to check if a user liked a Page directly in a Page Tab/App, but that flag was removed.
I have a simple tab page, php sdk working and I know I can get the "like" for this specific page from the user signed_request.
This page is a colaboration with another company who also has an FB page. What i´d like to know is if I can get the like status of their page for the current user so I can authorize an action on this tab that is dependant of the user liking both my page and my partner´s.
Is this possible without using an actual app, an access_token and the appropriate perms requested?
e.g. my page is fb.com/Coke and my partner is fb.com/Target
On this specific tab page I want to enable a button only if me (Coke) is liked (which I can get already) and if my partner (Target) is also liked.
I tried the graphAPI (me/likes) and FQL (using the connection table) and both compalin of an unauthorized request.
Short Answer:
No, this will not be possible in a production setting.
Further explanation:
Some users have their list of likes as public. In that case, it would work.
But in order to get likes from a user that has that setting as anything but public (such as myself, only friends of friends can see it), then it requires an app and an access_token that has a user_likes permission.
From the documentation:
Permissions Required:
user_likes permissions if querying the current user.
Previously, Facebook app's could check if a user liked a given page (for fan-gating) by calling the following Graph API method with no special permissions other than basic authentication:
/me/likes/page_id
This would return a data property with the page's details if the user has liked it previously, or an empty array when the user hasn't liked the page.
Seems that this has recently stopped working. Instead, the only way to get this information is, if the user_likes permission had been granted prior.
The same problem is encountered when using
/page_id/members/user_id
Is there any information on what's causing this new behaviour?
I'm guessing here, but the 2nd call you list would imply that the current user had rights to veiw your page's members list. Really the list of people who like a page should be restricted to the page owner although Facebook does show you who of your friends likes the page as well.
As for user liking the page, I've been searching today for the same and this answer seemed to be the best so far:
StackOverflow: Check if user likes page via Graph API
Similar to the ever-trendy Fan Page trick that allows page owners to only show certain content when a user performs the 'like' action (visible-to-connection), I wish to be able to only show certain content on a website once a user has liked the website.
If there is no FB code for this, I have considered using a Facebook like callback (triggered when a user likes on the current page) to set a cookie that establishes a user has liked the page or perhaps a database table that sets a users status to 'liked', again using the callback within the documentation.
Any ideas would be helpful. Thanks.
I haven't seen a "fangate" implementation for non-Facebook pages that didn't require you to go through the full Facebook authentication process (with the user_likes scope) first. You could set a cookie when they like, but that'll only work if they liked it via your site (i.e. if they liked you on Facebook, it wouldn't get caught by your site), and the cookie could get deleted or lost.
you can use the Javascipt SDK to easily accomplish this.
First, call FB.init:
https://developers.facebook.com/docs/reference/javascript/FB.init/
Then call getLoginStatus:
https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/
If they're not logged in ( not authorized your app ), then call
FB.login and then recall getLoginStatus.
If logged in, then get the user's likes via FQL:
https://developers.facebook.com/docs/reference/javascript/FB.Data.query/