Getting user likes of stream items via FQL (posts, comments, pictures, links, etc)
Solution 1
Here's what I've come up with, as of the time of posting (10-22-2012):
For friends/subscribedto/pages items:
SELECT likes, post_id, actor_id, target_id, message
FROM stream
WHERE source_id IN (SELECT target_id FROM connection WHERE source_id=me())
AND likes.user_likes=1
OR
From 'like' table:
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
But post_id
is always null and object_id
doesn't exist sometimes when queried via the graph api (i.e. graph.facebook.com/OBJECT_ID
)
For links/external objects - There is no direct way to get the facebook post details from this, but it returns a lot of results. Maybe with another query / multiquery looking for these urls in the stream or link tables.
SELECT url
FROM url_like
WHERE user_id=me()
Solution 2
I found a solution using the Open Graph API. Hope this will help you also?
To perform this action you need the users read_stream permission.
Please let me know if my solution works for your requirements.
Because FQL will not be longer supported than V2.0, I would prefer using Open Graph API over FQL.
/*
*
* Count my_user_id likes in wall of user "123"
*
* ex: url = /123/posts
*
* setTimeout to avoid exceed api level rate limit, code 613
*/
function findMyLikes(url,my_user_id,count,callback) {
console.log(url);
FB.api(url, function (response) {
if (response.data) {
response.data.forEach(function (post) {
//console.log(post);
if (post.likes) {
post.likes.data.forEach(function (like) {
if (like.id == my_user_id) {
count++;
}
});
}
});
}
if (response.paging && response.paging.next) {
setTimeout(function() {findMyLikes(response.paging.next,my_user_id,count,callback)},1000);
} else {
callback(count);
}
});
};
I noticed that this solution may take some time, if your are analyzing very long feeds. For this issue I have still an open question pending : Getting all likes from a specific user on a news wall with fewer graph API calls https://codereview.stackexchange.com/q/58270/50013?sem=2
DMCS
Senior Software Developer (Only called "senior" because I keep forgetting stuff) "Damn it Jim. I'm a programmer, not a server admin!"
Updated on June 04, 2022Comments
-
DMCS almost 2 years
I need assistance in getting user likes of stream items via FQL. I've got some of the likes coming back, but cannot figure out how to get others. For the access_token, every permission is granted.
Let me show you what I've been able to do:
postings I've liked on Page feeds:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT target_id FROM connection WHERE source_id=me() and is_following=1) AND likes.user_likes=1 LIMIT 10
Note: This worked as of mid Dec 2011 when the original question was posted. Now (mid Feb 2012) it is no longer returning anything liked stream content from a page.postings I've liked of posts that I posted:
fql?q=Select post_id, source_id, message FROM stream where source_id=me() AND likes.user_likes=1 LIMIT 10
Here's what I'm missing
postings I've liked on friends' walls:
fql?q=Select post_id, source_id, message FROM stream where source_id in (SELECT uid1 FROM friend WHERE uid2=me()) AND likes.user_likes=1 & LIMIT 5000
postings I've liked on events' walls:
????
postings I've liked on groups' walls:
????
-
DMCS over 12 yearsAs noted in my question, I can get three sub-sets of likes by using FQL (FQL is accessible using the Graph API, try for yourself in the graph API explorer). I just need to get the 2 missing sets of likes as I have documented in the question.
-
DMCS over 12 years"I would suggest you pic Ashton Kutcher and try to query on his like table... Wait, you need his permission" I'm not trying to query anyone's like table other than that of an authenticated user who has accepted every permission possible. This app, I inherited, allows a user to like/unlike stream items in Facebook. It doesn't currently store this because they envisioned that Facebook would be able to return that data. Now that it's been handed over to me, it is starting to appear that we will have to store the like on our side when a user likes something via our UI.
-
DMCS over 12 yearsDid you get a chance to try the three queries that actually do return liked stream items? FWIW, the me/likes I've already documented in the original question as to returning pages and other objects...just not stream items that have been liked
-
borisdiakur over 12 yearsThe suggestion with Ashton Kutcher was just a bit of fun - sry. My real suggestion is: Stick to your plan and store the users and their likes in your database.
-
Jeff Sherlock over 12 yearsI didn't provided enough context in my answer. I've updated the answer to make more sense. I'm referring to open graph objects a person has liked. If you go to cnn.com and "like" an article, we don't return that in the likes endpoint in the Graph API.
-
DMCS over 12 yearsHow would I get my own likes of friend's stream items (photos, posts, etc) via FQL? Or my own likes of event stream items? I can get my own likes for page's stream items and my own likes of my own stream items.
-
DMCS about 12 yearsAh, interesting. I'm going to research this further.
-
DMCS about 12 yearsPlease read my edits about the like table no longer being my question as it's very obvious that facebook has removed the ability to get that information. Please read my working examples of what I can get. As a matter of fact I'm going to edit my question so it is more clear as to what I need as I've not quite got it worded correct as your answer as well as the other peoples answers tell me I have it misworded.
-
DMCS over 11 yearsCan you tell me, Ajit, which likes your query will return?