Facebook Graph api /me/home : Not reliable - facebook

We are encountering an issue during the current Hackathon in my company. We access to our newsfeed through the FQL.
When we try to access to some old (but not so much!) informations, we are confronted to a problem: sometimes we have some datas returned, sometimes not.
That's a big deal for us cause it makes our project non reliable.
Example:
fql?q=select source_id, message, attachment, created_time from stream where filter_key="nf" AND created_time < 1323648660
Sometimes returns:
{
"data": [
]
}
Sometimes returns a list a 25 datas as expected.
Look like a wrong cache management?
Is this an open bug for FB ? It's kind of critical.
Hope you will be able to help me,
Regards,
François JAGUELIN

Limit the source_id to one user, for example:
fql?q=select source_id, message, attachment, created_time from stream where filter_key="nf" AND created_time < 1323648660 AND source_id = XXXX
When you don't limit the source_id to one user, the time you query over is greatly reduced. If you need to query over multiple source_id's, pack single source_id queries into a multiquery.
From FbDevWiki...
*The stream table is really two concepts built into one table. If you specify a filter_key and/or multiple users, the results will behave like the stream in Facebook's home page. If only one user is specified, and no filter_key is specified, the table will assume that you want a profile-like view, and all that implies.
Those behaviors differ significantly. For example, the homepage-like view only aggregates data over the last few days. The profile-like view gets much older data from our databases.*

Related

Get Facebook page's stream from a Global Page

I have a little problem with the Facebook api.
I am doing a very simple FQL request to get a Page's stream like this one :
SELECT post_id, type, likes, comments FROM stream WHERE source_id = X
It works just well. But, when I do the same request on "huge pages" like Coca Cola or Starbucks, all stream posts have an empty "type", "likes count" and "comments count".
I don't really understand why. I am thinking about a "Global Page" with country code error, but I just can't find information on this.
Any idea ?
Edit: just try another request to get the page global child IDs, but looks like Coca Cola and Starbucks doesn't use the Global Page system.
starbucks?fields=global_brand_children.username,global_brand_parent_page
So, any idea why my first request return empty infos when getting stream content ?
There is nothing wrong with "huge pages". It's only that "huge pages" have a lot of posts and shares from fans. Indeed, the stream table provides ALL the activities of the page.
The type of a stream activity will be null when the content comes from a user. When it comes from the page owner, it will be an int. See the description of the type field on https://developers.facebook.com/docs/reference/fql/stream/.
The reason why you might get a null as a like count is that you came across a post which has the can_like or can_comment fields set to false. These posts cannot be liked or commented because they are present outside of the page (i.e. on a user timeline or on particular website) and their owner didn't allow public likes or comments (even if publicly visible). If you are going to find such activities in the stream of the page is because they tagged the page in their message or photo.
Edit in answer to your first comment.
Question: why doesn't the following query give back the posts from the owner of the page:
SELECT actor_id, message
FROM stream
WHERE source_id = 40796308305
AND actor_id = 40796308305
Let's see how many results this query CAN give back:
SELECT actor_id, message
FROM stream
WHERE source_id = 40796308305
Okay, we get 17 results. Why 17? I don't know.
When you add AND actor_id = 40796308305 to your request, it will checks among these 17 results which ones have 40796308305 as an actor_id.
Answer? None!
Because it only checks the 17 first results, you'll have to indicate a LIMIT:
SELECT actor_id, message
FROM stream
WHERE source_id = 40796308305
AND actor_id = 40796308305
LIMIT 100
And there you get what you want.
This is one of the Facebook API's subtlety. Documented here: https://developers.facebook.com/blog/post/478/

Getting all one's 2012 shares with FQL

I need to retrieve among other data all the shares a person has done on his facebook account during the past year, 2012 in my case.
I found that shares are accessible via FQL table named "stream", selecting stream.type = 80. Using also the where clause on "created_time" and source_id should do the trick :
SELECT post_id,message,likes,attachment
FROM stream
WHERE source_id = me()
AND created_time > 1325397600
AND type=80
ORDER BY likes.count desc
Fact is... When querying the stream table, facebook's engine seems to need a limit. If you don't provide one, no result. I guess it's because if no limit is set, response times could be veeeery long... Anyway I'm sure they have many reasons for that. So :
SELECT post_id,message,likes,attachment
FROM stream
WHERE source_id = me()
AND created_time > 1325397600
AND type=80
ORDER BY likes.count desc
LIMIT 100
But: this limit parameter seems to be applied before some of my where clauses, unlike in SQL statements such as SQL server, it means that what fb does with my example query is sequentially :
take 100 elements from stream quite randomly, of any type (could be status, shares, photos, places, posts on your wall from friends, etc.) and any time. Actually, my source_id clause seems to be applied before limit.
then filter by type 80 and created_time, but not sure how
In my case, I need all shares from year 2012, but I can never be sure that some arbitrary limit set to 2000 or 5000 will catch all one's 2012 stream elements before applying the filter.
Maybe there is an other way ?
Thanks a lot for your help.

Facebook IN clause in FQL query

I have a big problem with Facebook FQL, if i do
select message from stream where source_id=175102475936031
I can get the correct data, if i do this
select message from stream where source_id IN(175102475936031,etc,etc,etc)
I got a empty JSON, why? is there any alternative to this select? I have to read the messages from multiple events.
Is your problem solved?
"IN" query is a supported feature of FQL. I have tried it multiple times.
Only needs to have:
column indexable
needs to have permission to access data
data should be present for at least one column :P
select message from stream where source_id IN( 175102475936031, etc, etc, etc)
"NOT IN" is not a supported feature of FQL. Ref: http://forum.developers.facebook.net/viewtopic.php?id=1420

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.

What's the query to get a list of a user's own posts that they have Liked?

Yes, I know that it's unusual for a user to "like" their own posts but that's what I'm looking for. I also know that you can't query the like table by user to get everything they've liked but that's not what I'm after. I just want their own posts (and later, photos) that they've liked.
I've clearly gotten pathetically rusty in my SQL skills--playing around with statements based off of the examples I've found:
SELECT source_id,message,created_time FROM stream WHERE source_id=me()
and
SELECT actor_id, post_id, message FROM stream WHERE uid IN (SELECT uid2 FROM like WHERE uid1=me())
I imagine what I want is either trivial to do or currently impossible. I expect the former.
To get the post ids that the user likes, it would be something like:
SELECT post_id
FROM like
WHERE object_id in (SELECT source_id FROM stream WHERE source_id=me())
AND user_id = me()
You could expand this to also include photo ids. And you could nest it another level deep to get more post info by using the like's post_id field.