FQL: retrieve objects from stream table that user liked - facebook

As described in the sample on documents, we can retrieve the user's news feed as below.
SELECT post_id, actor_id, target_id, message FROM stream WHERE source_id in (SELECT target_id FROM connection WHERE source_id= AND is_following=1) AND is_hidden = 0
What I want to do is to display user's news feed and when user clicks "my favorite", display the summary(all posts that a user liked).
Any idea?
Thanks.

Add this criteria to your query AND likes.user_likes = 1
and you should get it.
From example i do this to get all that i have liked in my wall:
https://api.facebook.com/method/fql.query?query=SELECT post_id, message, likes FROM stream WHERE source_id = AND likes.user_likes = 1 limit 50&access_token=
The same applies to the above.

Related

Getting public page's posts (timeline) using FQL

I try to get posts for a public facebook page using FQL:
SELECT post_id, created_time, type,like_info.like_count,comment_info.comment_count,message FROM stream WHERE source_id ='118074121050' and like_info.like_count > 800
118074121050 is the ID for public page https://www.facebook.com/cliomakeup
The token i use allows to read stream.
The result of the query just one post while there are many posts with over 800 numbers of likes (according to the page's timeline).
The question is why the fql result does not show me all the posts as they're public?
The stream table also gives posts by users, which doesn't look like being what you need. In order to filter posts from the page owner only, you need to specify the actor_id as being the same as the source_id:
SELECT post_id, created_time, type, like_info.like_count, comment_info.comment_count, message
FROM stream
WHERE source_id = '118074121050' AND actor_id = '118074121050'
AND like_info.like_count > 800

Facebook FQL: Get the post_id where a photo with ID XXX is used as attachment

I have a special problem and hope, someone can help me out of this.
My target: I have an object_id of a photo (and the pid and aid) and I want to know which posting on a page has this photo as attachment.
My current status:
SELECT post_id, actor_id, message, type, attachment FROM stream WHERE 1
AND post_id = "111111_222222"
AND source_id = 111111
AND attachment.fb_object_id = "111111_333333"
AND type = 247
This leads me to the posting, which has the photo as attachment. Obviously, cause I am searching with the "post_id".
But if I remove the 'AND post_id = "111111_222222"' Facebook sends me no data.
SELECT post_id, actor_id, message, type, attachment FROM stream WHERE 1
AND source_id = 111111
AND attachment.fb_object_id = "111111_333333"
AND type = 247
Does anybody know, how to get the post_id where a photo with ID XXX is used as attachment.
Thanks for your patience.
This is tricky because stream only goes back so far. This seems to be more of a bug / unstable nature of FQL data.
Try your call with this
SELECT post_id, actor_id, message, type, attachment FROM stream WHERE 1
AND source_id = "80329313253"
AND attachment.fb_object_id= "80329313253_11264130"
AND type = 247
And you can see it works.
Consider filing a bug to see what Facebook employees have to say about it

Getting user likes of stream items via FQL (posts, comments, pictures, links, etc)

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:
????
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()
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
#Jeff Sherlock, a partner engineer at Facebook, says here that 'you cannot pull all of the likes of a person using the fb platform. We limit it to actors, movies, sports teams, etc. for privacy reasons.' I know it doesn't make much sense since you can query all kinds of other stuff with the Facebook API. I would suggest you pic Ashton Kutcher and try to query on his like table... Wait, you need his permission ; ]
The problem is that the like table returns a blank post_id for everything. However, it does return an object_id for your likes.
You can put all these object_ids in a comma separated string, then submit a graph API call with ?ids=objectid1,objectid2,objectid3 etc.
This will then return all the objects that it finds. This way you can get the likes for stream items.
It seems to go about 4 weeks back. I can't seem to make it go any further back than this.
As an aside, one thing you will find is that liked comments are also returned as object_ids in the like table. However, there does not appear to be any way at all to find out the object details of these object_ids. Bit of mystery with these ones.
If you read the like table documentation, post_id field has a note which reads :
These post IDs must be queried from the stream FQL table.
Hence when you compare post_id like post_id<>"", it won't return you anything as default result contains blank post_ids. And it seems when you run below query :
SELECT user_id, object_id, post_id
FROM like
WHERE user_id=me()
It returns the pages liked by user and some other stuff but not the feed posts.
As you already want to get likes from stream table, you just want to get post_id from stream table. To get post_id of NewsFeed for a given day, you might want to try below query.
SELECT post_id
FROM stream
WHERE filter_key IN (
SELECT filter_key
FROM stream_filter
WHERE uid=me()
AND type='newsfeed'
)
AND is_hidden = 0
AND description<>''
You might want to use Limit and Created_time fields to get more no. of posts. And once you use above query in Multi-query to get likes for the user, you'll definitely get likes for a given day.
SELECT post_id, actor_id, message, type, permalink, attachment, likes,
comments, description, updated_time, created_time
FROM stream
WHERE filter_key in (
SELECT filter_key
FROM stream_filter
WHERE uid=me() AND type='newsfeed'
)
just change type on your requirement
This is not possible with the GraphAPI. The GraphAPI will allow you to see the pages that a user has liked with /me/likes, but it will not give you a list of all the items posted to the user's wall that they haved liked.
You can see details on this in the Facebook Documentation.
I have no experience with FQL as listed in your question, but a Stack Overflow question seems to provide an answer to your question.
See: Facebook API - "All my likes" query
Worked perfectly in testing.

Filtering newsfeed to be specific type using FQL

I'm trying to submit a query for a specific type of status sent to a user's newsfeed, where type=video. I basically want all videos posted for a user, including those not hosted by FB (otherwise I would submit a videos query). I would like it if I could get FB to not return anything except videos, but I certainly don't see a solution for that. I don't see that the returned query even has a field that will contain this information, so that I can filter the returned info. Is there any field in the stream table that will tell me the type of post?
Here's my initial starting point for the query:
SELECT post_id, from, name, source, link, picture, updated_time, comments
FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid=me()
AND type='newsfeed') AND is_hidden = 0
You can set a type for the stream (see ref), but video (type = 128) will return only uploaded videos.
SELECT post_id, source_id, actor_id, target_id, message, attachment, permalink, type
FROM stream
WHERE source_id IN (SELECT target_id
FROM connection
WHERE source_id = me() AND is_following = 1)
AND is_hidden = 0
AND type = 128
This is in contradiction to using the graph api (e.g. js sdk: FB.api('/me/home', function(response) {} )), where type: 'video' is given to attached video links (e.g. YouTube)
However, the attachment.media[0] field, identifies video links as being type: video; but that is an array (and I didn't know how to query in them) so I checked if the link contained a reference to youtube (youtube links can be long-form or shortened, youtu.be)
SELECT post_id, source_id, actor_id, target_id, message, attachment, permalink, type
FROM stream
WHERE source_id IN (SELECT target_id
FROM connection
WHERE source_id=me() AND is_following=1)
AND is_hidden = 0
AND type = 80
AND strpos(attachment.href, "youtu") >= 0

FQL to search newsfeed

I am having a strange issue with an app that I am developing. I am using PHP SDK to call the Graph API on server side and here is my code that calls the API:
$params = array('q' => 'George', 'limit' => 100);
$newsfeed = $facebook->api('/me/home', 'GET', $params);
And next is the code to render HTML of the newsfeed. I have a footer below that once clicked, loads further posts. But what I have observed is that in case of searching the newsfeed by providing additional 'q' parameter, we do not get results beyond one week.
Now I am giving a second try to FQL instead of Graph API. Good thing with Graph API was that appending a q parameter to /me/home would do the searching for you automatically and you had nothing to do. But with FQL, this does not seems to be the case as per the following documentation suggests:
http://developers.facebook.com/docs/reference/fql/stream/
My idea is to use following FQL:
SELECT post_id, actor_id, target_id, message, comments, likes FROM stream WHERE filter_key in (SELECT filter_key FROM stream_filter WHERE uid = me() AND type = 'newsfeed') AND strpos(message, 'facebook') >= 0
Any ideas how the search can be implemented? I actually want to emulate the news feed within the application so please enlighten me about batching multiple FQL queries if you have any ideas on that.
try to set the source_id = me() like this:
SELECT post_id, actor_id, target_id, message, comments, likes
FROM stream
WHERE source_id = me()
AND strpos(message, 'facebook') >= 0