check if user likes a page without application perm request - facebook

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.

Related

GET List Likes Using Graph API Explorer

I want to search the user's list of likes, to know if he liked my page or not
https://graph.facebook.com/v2.10/me/likes
I also want to know I did not follow my profile or not
https://graph.facebook.com/v2.10/me/???
There is no way to check if someone follows your profile. For getting to know if a user likes your page, you would need to authorize that user with the user_likes permission.
To check if the user likes your page without going through the whole list, you can use the following API endpoint: /me/likes/[page-id] ... if it returns something, the user liked the Page.

Facebook API - post on page user 'likes'

using facebooks api... how do you post to a page a user likes on that users behalf... for example I have a user that likes a certain page. They can log into my app and make a post on that pages wall via my app instead of logging into facebook to do it.
If the user grants your app the publish_stream permission then you can post on his behalf on pages he likes (or pages that don't require to like in order to post).
You can try it yourself with the Graph API Explorer, just go there and click the Get Access Token button, then go to Extended Permissions tab, select "publish_stream" and confirm.
Then in the address field put a page you like, let's say southpark/feed and submit, you should see the feed of that page. Now, change the method to the left of the address field to POST and click the Add Field link and write in the name "message", enter a value and submit, you should get an id of the post as a result.

Does /me/likes/page_id require user_likes permission?

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

Show content on external website, only if user is a 'fan' of the URL?

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/

Can canvas check if user has liked a certain page?

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