Facebook Graph API - determine if user liked a wall post - facebook-graph-api

I'm trying to make a small button in an Android app that lets the user like a wall post. I would like it to show if the user has already liked the post so the user knows that it's worked. The API here:
https://developers.facebook.com/docs/reference/api/post/
shows how to add and delete a like for a particular post but there doesn't seem to be a way to query the like state.
Calling:
https://graph.facebook.com/me/likes/19292868552_10150189643478553
seems like the obvious solution but this gives a parser error.

There IS actually a solution for this. You have to use FQL. Here, this is what will work
select user_id from like where object_id=your object_id AND user_id=me()
If the result returns an empty array, then the user never liked the post, if it returns a result, the user has liked the post. Simple :)

i think you want this: https://graph.facebook.com/19292868552_10150189643478553/likes ... or did i misunderstand?

Related

Get Facebook Comments via the Graph Api

Im trying to get Facebook comments using the Graph Api.
I've researched online and found an example that works but there's one thing that about it that I can't find any information about it.
Here's the Example that works:
https://graph.facebook.com/19292868552_118464504835613/comments?access_token=ZZZZZZZ
https://graph.facebook.com/XXXXXXXXXXX_YYYYYYYYYYYYYYY/comments?access_token=ZZZZZZZ
How do I get XXXXXXXXXXX_YYYYYYYYYYYYYYY ?
Is it the UserId concatenated with the Comment Id, is it returned by the Graph Api?
Why is there practicaly no information on this?
In the case of getting a page's post_id you can make a call like this to get the post_id.
https://graph.facebook.com/v3.2/{pageId}/posts?access_token={accessToken}
post_id looks something like this - 5704324444475_570454233326 and is in the id field of each returned post.
To get all comments for a page first you need to make a call to get all your posts and then make a call for each post to get comments.

Get all user details from facebook event with field expansion

I want to get all the user details from an event using the field expansion.
In pseudo code i think it should be something like this.
GET https://graph.facebook.com//attending.user(name,id,picture)
I can't get this to work (testing this in the graph explorer) Don't know if this is even possible.
Thx!
You need to use a url like this:
https://graph.facebook.com/EVENTID/?fields=attending.fields(id,name,picture)

Finding out if an Open Graph Object has been liked before

Is there anyway to determine if an object in Open Graph has been liked?
The documentation seem to imply that I have to post a like action on my object and expect an Error 3501 when it has been liked before.
From an UI pov this doesn't make sense, I want to change my like button ui to an "unlike" state without having to like my object and see if it fails or not.
Thanks!
If you're looking specifically for likes on an Open Graph Object (as in the target of an Open Graph Action), and you're talking about built-in (og.likes) likes, Shawn's answer is mostly right, but you need to look in a different FQL table.
An Open Graph Object is just a URL that resolves to a page that has og:type meta in its header. Facebook treats these as link objects (you can check this with SELECT type FROM object_url where url='http://url.to/your/object')
You can find interesting information in the link and link_stat FQL tables, but what you're looking for is the join table where Facebook relates user likes to links: the url_likes table.
So, to tell if the current user has liked a given Open Graph Object, you'd use:
SELECT user_id FROM url_like WHERE user_id=me() AND url='http://url.to/your/object'
If you get a value back, the current user has already liked it. If you get an empty array, the current user has not liked it.
To my knowledge, there's no way to do this with the Graph API, only FQL. I'd love to be proven wrong, though.
Depending on the object, if the object has a like connection you can user the graph api to determain if current user has liked the object.
i use fql in a similar fasion to check if a user likes a post.
/fql?q=SELECT+user_id+FROM+like+WHERE+post_id=\''.$postid.'\'+AND+user_id=me()
refer to post / like https://developers.facebook.com/docs/reference/api/page/

Getting all friends' pictures using the fields parameter doesn't seem to work?

I use the JavaScript SDK for Facebook Connect.
Yesterday I loaded all the friends of a logged in user like this:
https://graph.facebook.com/me/friends?fields=name,first_name,picture&access_token=MYACCESSTOKEN&callback=?
Using this code I got the id, name, first name and picture of all the friends that the logged in user has. This was called using AJAX/jsonp. As I said, it worked yesterday and no modifications have been done to the code since then.
Today I get the id, name and the first name - no picture(!) Could this be a glitch in Facebook Graph, has there been any updates that I could have missed or is the above call to the graph API invalid?
Is this a correct way to get the picture of all friends?
You're right, the picture field is not being returned anymore. However it is very easy to get the picture URL. http://graph.facebook.com/{friendId}/picture you can either call that to get it programmatically, or even have that graph call as the src attribute of the image tag <img src="http://graph.facebook.com/{friendId}/picture" />.
Update: Bug seems to be fixed now.
Once again, Facebook proves themselves. Why would anyone just remove something from an API without at least notifying people they are going to do it?
Fyi, I filed this bug report:
https://developers.facebook.com/bugs/269804093087242
My guess is that it gets ignored or closed as either a duplicate or wontfix and there won't be any recourse.
The issue with the workaround above is that img src url ends up being a http redirect instead of the absolute url like before. That just slows things down.

Graph user notifications. Get Post ID

I'm starting to use the Graph API to get my notifications, and in the REST interface, they had the object_id field. I used this to get the notification objects' id to then query the Graph for more information.
The Graph API object does not include this information.
Example of what I want to do:
Get user's notifications JSON object.
Grab single item
Identify if this item supports commenting/liking
Display comments and number of likes for that item
if user can comment or like item, display buttons for this
my process:
call me/notifications/?include_read=1
is pretty easy to do.
I can identify if the object refers to a group, event, random application, post, or photo using the URL. I know that posts, likes, photos and others support commenting/likes so I have a way of doing this, though it involves parsing the link attribute of the item
this is what I need help with. I can get the id of the object by parsing the link, but I don't get the full object some times using this. For example, to post on a comment, you need to have USERID_COMMENTID and the link only has the COMMENTID in this form http://www.facebook.com/USERNICKNAME/posts/COMMENTID
I also need help with this. I guess some fb objects can't been liked via the graph?
any help would be great!
The notification FQL table, which also replaced the REST notifications.get API, still has an object_id column. That's the closest thing that exists to what you're asking for. It doesn't look like the Graph API call is documented to have the object_id field unfortunately.