Facebook Api getting feeds and comments - facebook

I'm trying to get the feeds on a public wall and the associated comments.
So every X minutes I'm doing a query in order to get what's new (feeds and comments).
I need the feeds (the new feeds since myDate) and comments (comments posted on the new feeds and comments posted on older feeds).
So if someone posted a comment on a older feed I want to get it.
I tryied to do this using FQL and Graph API but I don't manage to find the best solution.
With FQL there are some problems (bugs) with LIMIT and OFFSET and does not work very well.
With the Graph API I don't have so much power.
So this is what I've tryied:
https://graph.facebook.com/PAGE_ID/feed?access_token=MY_ACCES_TOKEN0&limit=500&since=1350033469&until=now&updated_time>1350033469
This gives me the newest post, so no problem because for each one I'm doing a new query in order to get the comments for each feed:
https://graph.facebook.com/PAGE_ID/comment?access_token=MY_ACCES_TOKEN0&limit=500&since=1350033469&until=now&updated_time>1350033469
The problem is that if a comment is posted on a older post, I don't receive it.
Using FQL I cannot filter only the newest posts (based on my since date) and the posts with new comments.
https://api.facebook.com/method/fql.query?query=SELECT post_id, text, fromid FROM comment WHERE post_id IN (SELECT post_id FROM stream where source_id=PAGE_ID and comments.created_date>1350033469)&access_token=MY_ACCES_TOKEN
Using Graph API I have a good pagination (using next and previous links inside the response) but with FQL I did't find any solution.
So anyone have some idea ?
Thanks.
C.C.

First, the FQL is deprecating, so you need to use only the Graph API.
The solution that I came with, is that when you already have a post, you need to recheck the post with its unique ID, and that request gives you two times, created_time and updated_time, so you need to check if your updated_time changed.
The pagination given in the Graph API is for only posts, so when posts have new comments, they won't come first in the list, you need to find them yourself.
-- UPDATE --
Use batch_requests to achieve this, so you can make more requests at a time.

Related

FQL get posts from stream on updated_time, need to find equivalen Graph API

FQL will be obsolete in API 2.1. If any user creates a new APP, then the user is forced to use API 2.1 features, as a result, I need to remove all FQL and replaced with Graph API to server the new users who create a new app.
Here is the quesion, We use FQL to fetch all posts on wall based on updated_time, and then we can fetch all newly comments reply to these posts on the page. This is the way we can fetch all the newer comments since last update. the FQL syntax look like this.
https://graph.facebook.com/v2.0/fql?q=SELECT post_id, comment_info FROM stream WHERE source_id = ' owner ' and updated_time >=' since
Does any one know the equivalent feature in Graph API. I have been looking documents but unable to find it. Please help in coming out an alternate approach to achieve the same functionality, Thanks.
There's unfortunately no equivalent in the Graph API. The since request parameter is relative to the created_time AFAIK.

How to limit Facebook Graph API to only posts (not comments or likes) by user without using FQL?

I am trying to query the FB graph API for all of my posts. I would like the result set to only feature items that I've posted on my timeline. Not other users, and not my likes or comments.
The documentation is extremely confusing and most of the knowledge I've gained is through trial and error. To date, the only proposed solutions to this I've found online require the use of FQL (such as in this similar question: Facebook graph api- how to get user feed,with out posts about likes and comment by the user?) however the FB documentation states that FQL is deprecated and will not be supported in the future so I would like to avoid it. Additionally this is currently structured as a url request and if at all possible, I would like to keep it so.
To date, I've tried:
/[userid]?fields=posts.limit(100).fields( picture, link, created_time, from, message, description, object_id )
which will get me all of my posts with the data fields I require, but it also includes "Likes" and when I "Comment" anywhere - which I don't want.
/[userid]?fields=feed.limit(100).fields( picture, link, created_time, from, message, description, object_id )
which returns only posts - but also includes posts made by others on my timeline (and I don't want those either).
It seems unclear to me if there is any more robust way to work with these different feed types as documented:
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed/
Can anyone tell if there is a way to either limit the "feed" edge to only my posts (not including others posting to my timeline) or filter the "posts" edge to remove the "likes" and "comments"?
Instaead of /feed, you can use /posts.
More info here:
https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed
It's not possible as far as I know to generally apply filters to the Graph API calls, except very little exceptions.
/user/feed is an example (https://developers.facebook.com/docs/graph-api/reference/v2.0/user/feed/#read), where you can specify either with=location or filter={stream_filter}.
{stream_filter} in this case is a result of the filter_key field of the following FQL query:
select filter_key, name from stream_filter where uid=me()
Maybe you can try
GET /me/feed?filter=app_2915120374
which should give you the status updates.

How to get Page's Posts by Others

I need to pull the 'Posts by Others' from my Facebook Page and display them on my site. Spent the afternoon fiddling around with the API and was able to see posts made by the page, but not others. Any ideas?
Steve, I just found another solution, you can use the Graph API using FQL.
Just make a call to the following:
https://graph.facebook.com/fql?q=SELECT post_id, created_time , app_data, type, actor_id, target_id, message FROM stream WHERE source_id = YOUR_PAGE_ID AND actor_id != YOUR_PAGE_ID&access_token=YOUR_ACCESS_TOKEN
If you need more variables, you just need to put them after SELECT, and you can check them out here: https://developers.facebook.com/docs/reference/fql/stream
On iOS, you don't need to put the access token in the query. To check how to do it with the latest iOS SDK, see my answer here: https://stackoverflow.com/a/14357179/675486
Got it, they are in the 'feed' field along with posts by the page. I was hoping for something that would just give posts by others, but I can filter out the ones posted by the page.

Retrieve ALL Facebook Comments for website/App ID Using Graph API (i.e. get latest comments)

I'm trying to create a feed of latest comments for a website. I don't have any problem getting comments on a per post basis but I don't seem to be able to find any way to get all, or at least the last 10 comments for the entire website.
Obviously I'd like to do this in the simplest way possible and I figured this would be via the Graph API.
Any suggestions appreciated.
Thanks
I think you might have to enter all the URLs, but it can be done via FQL using the comments and link_stat table.
SELECT xid, text, username, time
FROM comment
WHERE
object_id IN
(SELECT comments_fbid FROM link_stat WHERE url IN (All_your_URLs))
Can you try the above and see if it works ?
Reference - Comments & Link_Stat

How to check if a Facebook page post shared by a certain user?

I need a way to learn if a user had shared a post (link, video, photo etc.) which is published by a Facebook page. I have the object_id and link of the post, and user_id of the user considered. Is there a Graph API or FQL (or something else) solution to ask Facebook if the user re-shared the post or not? Or is it possible to get a list people who shared the post? So, I can extract my answer from this list.
Note that I know it is possible to find the answer by crawling the user's wall feed. But it is time consuming and I need a more efficient way.
Thanks in advance.
You can use the following FQL to get the data you're looking for.
SELECT via_id, created_time, owner_comment
FROM link
WHERE owner = me()
You can then compare via_id against the posts author (page ID) to determine if this share came from the page in question.
Unfortunately, there seems to be a bug with the data return where some of the via_ids come back as 0. There is a ticket in with Facebook which, at the time of this post, has been open for three weeks at medium priority. I have no idea if this issue is specific to my app or affects everyone, but that's the query to get what you want.