facebook graph api if a user has liked a page - facebook

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

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.

Is it possible to get reviews made by a user on Facebook via Graph API / FQL?

Despite all my research, I can't find a way to get this data via Graph API.
It seems that no permission matches with this...
Any idea ?
https://developers.facebook.com/docs/graph-api/reference/v2.2/page/ratings
Keep in mind that you need a Page Access Token for this, so you must be Admin of the Page. No extra permission needed, just manage_pages to get the Page Access Token, of course.
Getting the ratings for a specific User without accessing a Page is not possible afaik.

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

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

Get all posts on a friend's wall

I'm trying to find an API call (or set of calls) that will allow an app to get the posts that one would see if viewing a friend's wall. Either a REST call or a FQL call would do.
I tried /feed and /posts, compare the results with what I see on my friend's wall, and the results I get from it are incomplete.
I know this is possible because apps like Friendly are able to do it.
Any hints?
Well, there's two different API endpoints for querying the posts of a given user; home and feed. Home includes posts from other people and pages (basically what you see when you log in and go to your home page) and feed is the stuff the user is sharing. Assuming your application has authenticated the user and they've allowed the read_stream permission, you can then make queries to the Graph API using their access token:
https://graph.facebook.com/{SOME_USER_NAME}/home?access_token={SOME_ACCESS_TOKEN}
and
https://graph.facebook.com/{SOME_USER_NAME}/feed?access_token={SOME_ACCESS_TOKEN}
The only hint I could give you is that "incomplete" is pretty standard with the Facebook API. You can only do the best you can with what they give you. Counts will be wrong. Data will be wrong. It's a fluctuating, moving target, so code to that fact.
You can interact with posts by retrieving the read_stream and publish_stream for a given User's ID.
Once you have the ID of the User that you are interested in you can use FQL to retrieve posts from streams that you have the permissions for.
This stackoverflow answer goes into more detail and contains further links to the documentation on the Facebook Developers site.
We do it like this:
1) we use Facebook Platform PHP5 client
2) then what you do is:
$this->facebook = new facebook($key, $secret);
$out = $this->facebook->api_client->call_method("facebook.stream.get", array('viewer_id'=>0, 'source_ids'=>$uid, 'limit'=>$limit));
then just operate with out, which contains all posts on asked page.
but, afaik, it will work only with pages, not with normal users. but dig that way to get answer.
You should make a graph call to https://graph.facebook.com/< FBID >/statuses?access_token=xxxxx
Here access_token shall have read_stream permission and offline_access permission ..