realtime api feed - how to get new comments? - facebook

I made it to subscribe to the realtime api and retrieve update messages telling me the uid and time when the item changed. But how do I get the corresponding post/comment. I tried to use the fql but unfortunately there seems to be a bug in the fql when using updated_time.
This is my query:
SELECT post_id, actor_id, target_id, updated_time, message FROM stream WHERE source_id = me() AND updated_time >= "pushTime"
where pushtime is the time I got from the realtime notification.
It works for getting a standalone(no comments) post but as soon as there are comments it does not work. When I go through all posts and check the updated_time I can find the correct post.
My only solution for the time being is to iterate over all posts until i find the post where updated_time == "pushTime".
Anyone another solution?

If you have stored previous comments then retrieve the last comment ID you have stored and use that to query facebook for comments with an ID higher than that.

Related

How to filter user's news feed to posts/actions from a specific app in Graph API

I have a Facebook app and I want to filter user's news feed to get latest posts/actions that was posted using my app, in Graph API.
I've found this: How to get activity from my app with Facebook Graph API?
This one is okay for getting actions/posts by a specific friend (or the user itself), what I need is almost the same, with the difference that I need this "stream" by all friends of the user that use my app, not a single user.
Then I've found this: Facebook graph api : how to filter app feeds. For this one, the example in the question itself returns empty data for me (with the appropriate access token with read_stream permission). The only answer suggests to use FQL. I've tried SELECT post_id, message, comments, likes FROM stream WHERE app_id = MY_APP_ID and I got this error:
{
"error": {
"message": "Your statement is not indexable. The WHERE clause must contain an
indexable column. Such columns are marked with * in the tables linked from
http://developers.facebook.com/docs/reference/fql ",
"type": "NoIndexFunctionException",
"code": 604
}
}
How do I retrieve the list of all the last (say 100) posts from a specific app by the user and their friends, from the user's scope?
With all FQL queries, your WHERE clause must include at least one indexable field (those are marked with a star next to the field name in the docs) – for performance reasons.
So for the stream table you have a choice between source_id (id of the user whose wall the post is on) or filter_key. You can read the valid filter keys from the stream_filter table – but every user has the filter key nf for what shows up in their news feed. (post_id is also indexable, but of no use for us here.)
So you could try filtering with WHERE filter_key = 'nf' AND app_id = 'YOUR_APP_ID' – that should give you the posts that your active user is able to see in their feed that where made via your app.
You could also try with source_id, filtering that to either being equal to me() (your current user in FQL), or it being in the list of your friends (whose ids you can get from the friend table, again using me(), as a sub-query) - so like this,
… WHERE (source_id = me() OR source_id IN (SELECT uid1 FROM friend WHERE uid2 = me())) AND app_id = 'YOUR_APP_ID'
– but I think that will have less good performance, so I’d try with filter key first and see if that gets you the posts you want.
EDIT: So, as the questioner found out, using /me/home?filter=app_MY_APP_ID works apparently better, and is also easier. Whoever else might need this, they should use this version, since it is more reliable – FQL often gives less results then one would expect.

How can I get all my posts to other people, not to my timeline?

How can i get, using Facebook Graph Api, all my posts to other people, not to my timeline?
I'm trying to use me/posts , but i get all my posts including to my timeline, and i couldn't separate it
Using Facebook FQL API:
SELECT post_id, created_time, description, description_tags, app_id,
message, type, created_time FROM stream WHERE source_id=me() AND
comment_info.can_comment!='' AND actor_id=me() AND permalink="" AND
created_time<=now() LIMIT 150
The only problem is this query doesn't return "Upload photo on friends wall"'s post, because of this unresolved bug at https://developers.facebook.com/bugs/148353975327544. However, this FQL query should works perfectly. Kindly let me know if you're figure out something wrong with this query.
Also, please make sure your user access token have granted "read_stream" permission.
comment_info.can_comment!='' used to exclude "Comment on friend's Status" story feed.
permalink="" used to exclude "Lim and 林果皞 are now friends." or "People changed his profile picture.", "林果皞 created an event."...etc. You can test what would happen if remove this.
Update for comment below:
I think what you can do is extract the id from description_tags which was no start with "0", for example my screenshot, id "100003013144869":
Also, extract the created_time, for example "1368624514"
Then, do a query with:
SELECT post_id FROM stream WHERE source_id='100003013144869' AND
actor_id=me() AND created_time=1368624514
I'm know it's not absolutely accurate(If 2 feed have the same created_time on seconds), however most likely you can make your job done.

Unable to retrieve events created by a page

I have tried with EVERYTHING, graph, FQL, access_token with all permissions granted, multi-queries... now I'm really tired! Someone can tell me HOW to retrieve all the events created by a page like this? http://facebook.com/mammamiasantateresa
I want to know why this query doesn't work:
SELECT eid, name, description, location, pic_big, start_time, end_time, is_date_only FROM event WHERE creator = 229315807171062
But instead, this query with this page: 205712556144006 (/fifteenonline) who has only an event, or with Coldplay's page 15253175252 (/coldplay), who has many events, it just works!!! I wonder why. Nobody for weeks gave me a response. Please, it's very important for me. Thanks!
Your query is OK and if this would be an event it should be worked. But the thing you're looking for is a post on a wall, not an event, and it could be found via searching in stream in Graph API or FQL query:
Graph API request:
http://developers.facebook.com/tools/explorer?method=GET&path=229315807171062%2Ffeed
FQL Query request (with 2 fields, but anyway this post is there):
http://developers.facebook.com/tools/explorer?fql=SELECT%20message%2C%20updated_time%20FROM%20stream%20WHERE%20source_id%20%3D%20229315807171062

FQL query error 104

last week I needed to run a FQL query to return the last wall post of a public page, which is very basic
SELECT actor_id, message FROM stream WHERE source_id = 122338662806 limit 1
it worked fine, returned an xml schema and I then went to get the message from there. This is all done in the backend of a website, and not a facebook application.
Sunday night though, it stopped returning anything and started giving me:
<error_code>104</error_code>
<error_msg>Requires valid signature</error_msg>
which after some research, means it wants an access_token. Since this is not a facebook app, is there a way around this, since it's a public page?
Thank you in advance!
I don't know the way its done for public pages but adding an access_token worked for me
SELECT actor_id, message FROM stream WHERE source_id = 122338662806 limit 1&access_token=YOUR_ACCESS_TOKEN
this is what facebook says,
GET /fql?q=SELECT+uid2+FROM+friend+WHERE+uid1=me()&access_token=YOUR_ACCESS_TOKEN

How to fetch facebook users profile stream with php?

I am trying to get users profile stream via facebook api. I have read all related post that pop up is stackoverflow but did not found the answer. I am using simple fql for this.
SELECT actor_id, message FROM stream WHERE source_id = <user id> limit 50
This fql statement is from facebook developer site So it should work but its not. Note that i am not using facebook connect. But according to the site i should still able to get the public posts, right?
here is the code i am using:
$fql = 'SELECT actor_id, message FROM stream WHERE source_id = <user_id> limit 10';
$query = 'https://api.facebook.com/method/fql.query?query='.urlencode($fql);
$status = file_get_contents($query);
echo $status;
The error i am getting is failed to open stream in php and when i write the url in browser directly i am getting this error 104 Requires valid signature method fql.query query SELECT message FROM stream WHERE source_id =<user_id> limit 10
Also i need to know what command to use in FQL if i want JSON data format.
Facebook has recently updated the API so that it now requires an access_token to query the stream table using FQL. So your query won't work without an access_token.
See this blog post for more information.
To get a JSON response, add "?format=JSON" after your query.