I've a question in regards to the FB Graph API. Assuming I would like to search for the likes related to a Facebook post,I would have to do this:
541729512538864_792100727501740/likes/
But what If I would like to find whether a user(me) has liked that specific post(not page)?I've tried doing it this way.
541729512538864_792100727501740/likes/<my user id>
But it does not return any results.So what would would the actual Graph path be?I would gladly appreciate any help,thank you :D!
With the Graph API this is not possible imho. You'll need to use FQL instead:
select post_id, like_info.user_likes from stream where post_id="541729512538864_792100727501740"
will return
{
"data": [
{
"post_id": "541729512538864_792100727501740",
"like_info": {
"user_likes": false
}
}
]
}
in my case. This is always bound to the User of the Access Token you're using to running this query with. See https://developers.facebook.com/docs/reference/fql/stream/ for a reference.
Related
I am able to get share count and comments count but unable to get the likes count.
https://graph.facebook.com/?ids=MY_URL this API gives the response as,
{
"MY_URL": {
"share": {
"comment_count": 0,
"share_count": 13,
},
"id": "MY_URL",
}
}
In the same way, I just need to get likes count/ reaction count from API. Please help. Thanks in Advance
Check out the engagement field - https://developers.facebook.com/docs/graph-api/reference/v3.2/url
It returns four different counters - comment_count, comment_plugin_count, reaction_count and share_count.
The reaction_count would be the number of all reactions (like, love, sad, …) - that is as much “detail” as you can get in this regard for external Open Graph objects.
Example in Graph API Explorer, for the object http://example.com/:
https://developers.facebook.com/tools/explorer?method=GET&path=%3Fids%3Dhttp%253A%252F%252Fexample.com%252F%26fields%3Dengagement&version=v3.2
I am rather new to Facebook Graph API and I'm trying to find out if a user has liked a specific post.
Right now, in order to achieve this, I get all the likes for that post and then I iterate through them to find a match. But this procedure requires a lot of requests when the number of likes is too high, as the maximum number of likes per request appears to be 100.
Is there any better way to check if the user has liked the post?
Request the summary of the likes (post_id?fields=likes.limit(0).summary(1)), then you will get a data structure that looks like this:
{
"likes": {
"data": [
],
"summary": {
"total_count": 1,
"can_like": true,
"has_liked": false
}
},
"id": "…"
}
The properties can_like and has_liked reflect the values for the user who’s access token you used to make the request.
UPDATE
The latest version of Graph API today is v2.8. In this version you can get the reactions also. It is better to use reactions than likes as reactions also includes the Love, WOW and HAHA etc reactions which likes does not.
You can add the field for reactions's summary instead of likes's summary as below
fields=reactions.limit(0).summary(true)
Using this you will get the reactions summary as below
"reactions": {
"data": [
],
"summary": {
"total_count": 6,
"viewer_reaction": "LOVE"
}
}, ......
Notice the "viewer_reaction": "LOVE" which means you have given a reaction to the post which is LOVE. It's value could be any one of LIKE, LOVE, HAHA, WOW, SAD, ANGRY, NONE. The NONE means you have not liked the post.
Given a particular URL, how can I get the Facebook Share count for it?
There is one way to get the count, i know that platforms like sharedcount.com are using this:
https://api.facebook.com/method/links.getStats?urls={your-url}/&format=json
I highly suggest not using FQL anymore, it is deprecated and no longer available in v2.1+ of the Graph API: https://developers.facebook.com/docs/apps/changelog#v2_1_deprecations
Edit: This is deprecated, but there is another possibility: Get FB likes, shares and comments for a URL using PHP - with no limit
The easiest way to do this is to fire off a request to the Graph API.
The following query will select:
like_count
total_count
share_count
click_count
comment_count
https://graph.facebook.com/fql?q=SELECT%20like_count,%20total_count,%20share_count,%20click_count,%20comment_count%20FROM%20link_stat%20WHERE%20url%20=%20%27http://imdb.com%27
{
"data": [
{
"like_count": 62024,
"total_count": 191031,
"share_count": 93544,
"click_count": 71308,
"comment_count": 35463
}
]
}
Just replace the google.com with whatever URL you want to get the information for.
Status entry comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386582683,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185457974988272_294727","parent_id":185457974988272,"sender_id":106182246249179,"created_time":1386582683}}]}]}
Album comment:
{"object":"page","entry":[{"id":"106182246249179","time":1386581446,"changes":[{"field":"feed","value":{"item":"comment","verb":"add","comment_id":"185444231656313_190183","parent_id":185444231656313,"sender_id":100006218707108,"created_time":1386581446}}]}]}
They seem impossible to distinguish. However, the first one's real post id is pageid_parentid = 106182246249179_185457974988272. If you try to do the same thing with the album comment to get the feed from the stream FQL table, you won't get anything (or an exception with graph api).
Has anyone found a way to distinguish somehow between the two?
Yes.
First you need the object_id
object_id=pageid_parentid
Make this api call with the object id:
GET https://graph.facebook.com/v2.9/{object-id}?fields=type,status_type&access_token=token
The response should look something like this if the parent is a post:
{
"type": "status",
"id": "106182246249179_185457974988272"
}
If it's an album, it will look like this:
{
"type": "photo",
"id": "106182246249179_185457974988272"
}
I want to get the id and type of a Facebook object based on its URL.
My goal is to identify if a certain URL is a Facebook Event (for example https://www.facebook.com/events/258629027581347).
So if I had the object-id of that object I could do the following FQL query and know that if I get a result the object is an Event:
select eid from event where eid = 258629027581347
The problem is getting the object-id based only on the URL. I do not want to parse the id from the URL because there is no guarantee that the format of the URL will remain the same in the future. I want to find a way to do it through one of Facebook's API's.
After searching for a while, I found the following suggestions for how to do this, but unfortunately none of them work:
FQL query from the object_url table - the query yields no results:
SELECT url, id, type, site FROM object_url WHERE url = "https://www.facebook.com/events/258629027581347"
Use the graph api:
https://graph.facebook.com/https://www.facebook.com/events/258629027581347
This returns a JSON object containing only the URL - no id.
Use the graph api with ?ids= like this:
https://graph.facebook.com/?ids=https://www.facebook.com/events/258629027581347
This returns the following JSON, also no id:
{
"https://www.facebook.com/events/258629027581347": {
"id": "https://www.facebook.com/events/258629027581347",
"metadata": {
"connections": {
"comments": "https://graph.facebook.com/https://www.facebook.com/events/258629027581347/comments?access_token=AAACEdEose0cBADzSuuyJWohIwkXuvQGJUsIlSJz04J4nzKqqQXTvGiPXf4YDBPuh0rdyXgSWnWcJpN3X3GaATVLjG6UmZBiHKmcxCWwZDZD"
},
"type": "link_stat"
}
}
}
What am I missing here?
Thanks!
To my knowledge, there isn't an API method at this time that takes a Facebook URL and tells you what it is. The only way to go about this is to parse the URL and look for the last element and pass this to https://graph.facebook.com/258629027581347?metadata=1&access_token=XXXX
It's a noble goal that you are trying to build a future-proof Facebook application, but I don't think that is a possibility at this time. The Facebook platform is still evolving. There is less of a guarantee that the api methods will remain constant than the url struture.