FQL - How to fetch latest photos of all my friends? - facebook-fql

I'm trying to fetch latest photos uploaded by all my friends within last 24 hours using Facebook FQL query:
SELECT pid, caption FROM photo WHERE aid IN
( SELECT aid FROM album WHERE owner IN
( SCV list of all my friends Ids )
)
AND created > 1299341284 ORDER BY created DESC
1299341284 is 24hours back from time of writing this article
I get only few results (cca 20), not all photos. It seems like there is a limitation in number of statements in IN. I'm trying with 308 friends ids. If I put only few ids it works. Do you have any idea how to solve this in effective way? Probably using multi query? Any ideas?
Thanks

Use SELECT uid2 FROM friend WHERE uid1=me() instead of the SCV list.

Related

FQL get feeds from multiple users

I need to retrieve the wall posts of multiple Facebook Users . So far, I manage to retrieve the data from just one User but I need to get it from 60 users aprox. Here is my FQL query in objective C, I understand the query sintax is the same in every language:
[fql.parameters setObject:#"SELECT message,attachment FROM stream WHERE source_id in
(SELECT id from profile where username = 'zara' )" forKey:#"q"];
Please I need help! Thanks in advance.
You can do this by looking for updates in an array of usernames:
SELECT message,attachment FROM stream WHERE source_id in
(SELECT id from profile where username IN ('zara','zuck','theuncrunched','thepaulcarr'))

Photo tags query response of max 400 elements

i'm using new Facebook SDK 3.0 but it's not relevant since Graph API Explorer has the same behavior.
The problem is that when i try to fetch some user photo tags, like "me/photos" or the equivalent FQL query, i get a response of max 400 elements, using either graph or fql.
I already tried using LIMIT field (for example the FQL query is "SELECT src, src_big FROM photo WHERE pid IN (SELECT pid FROM photo_tag WHERE subject=me() LIMIT 1000) LIMIT 1000")
but nothing change.
I also tried with SINCE and UNTIL, but i understood that FB returns a table of 400 rows and then shrink it according to your query.
Is maybe another way to bypass this limit or for some unknown reason FB wanted it and it's not a bug?
Thank you

getting latest photos from friends not working

I tried getting the latest photos fo my friends using a method described here:
FQL - Can i get photos of my friends posted this week
At first it seemed to be working fine but then I noticed that some of the photos of my friends weren't being fetched even though they had a higher timestamp (the photos were being sorted by created field from photo FQL table)...
After a bit of debugging I noticed that the problem is in
SELECT aid FROM album WHERE owner IN
(SELECT uid2 FROM friend WHERE uid1=me()
if I pass a short list of my friends' IDs they are being sorted correctly, but when I pass a complete list not all friends are included in the query result...
Any ideas why this isn't working? Are there any limits on how many values can be passed in a "SELECT XXX FROM YYY WHERE ZZZ IN (?)" query?
Thanks in advance for any advice
The limit seems to be about 5000 records returned in any part of an FQL query.
Assuming you have fewer than 5000 friends, you could cut down on the number of albums returned by modifying your query to inspect the modified_major column to only return albums that have had a photo added in the period of interest. You could alternately look at the modified column to return any album modifications.
Also, it looks like aid and pid are on the path to deprecation. New development should use object_id for maximum compatibility.
So to get all albums that have had a photo updated since 2012-10-01, you could use this query:
SELECT object_id FROM album WHERE owner IN
(SELECT uid2 FROM friend WHERE uid1=me()) AND modified_major > 1349049600
In your outter query change aid to album_object_id and pid to object_id

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.

Facebook Comments Count

I am trying to write a Facebook query that will return all comments posted by a user to his friends,
however I can't seem to find the correct schema. Its as if there are no 'indexable' fields to build this.
Any suggestions please?
With thanks,
Wineshtain
The indirect path for stream comments would be something like
select * from comments where fromid = <my_id> and object_id in (
select post_id from stream where sourceid in (
select uid1 from friend where uid2 = <my_id> ) )
for photos, substitute the middle query with
SELECT pid FROM photo WHERE aid IN ( SELECT aid FROM album WHERE owner IN ( ...
Unfortunately the security settings may restrict the querying your friends wall posts and photos.
I don't believe you can accomplish this in a direct manner as you describe. FQL tables are generally only indexed on a limited criteria (for performance reasons I'm sure). In the case of the Comments FQL Table, you can only select comments via a post ID or an xid.
Unfortunately, this means that you have to know the objects that a user has commented on before you can get the comments for it. You would have to have previously selected all the posts, photos, etc. that you wished to get the comments for before you could retrieve them.