Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Facebook Graph API search using since updated_time parameter

I am using the Facebook Graph API in Python. Every post has two datetimes:

  1. created_date
  2. updated_date

When I am providing the since parameter, it is returning feeds where the created_date is greater than or equal to the since parameter. For example, if I provide since=2015-06-05 then it will return all the posts from 5th June, 2015 to now.

But suppose there is a post that was posted on 7th June, 2015 and few activities (likes, shares, comments, etc.) that happened on 8th June, 2015. In this scenario the updated_time of that post changes but created_time will be the same (7th June, 2015). If I pass parameter since=2015-06-08, then I won't be able to track all of the activity on that post.

Is there any solution by which I can pass the since parameter on updated_time instead of passing it to created_time?

like image 329
Sanjay Yadav Avatar asked Jun 13 '15 11:06

Sanjay Yadav


Video Answer


2 Answers

As @CBroe points out in the comments, this isn't supported by the Facebook Graph API. (It was previously supported using Facebook Query Language (FQL), but that's no longer available).

That said, with some creativity (and a bit extra code) a similar effect can be achieved by combining a couple of queries.

In my application, I perform a query with the following parameters:

  • until=2015-07-07 (or whatever the since date would have been)
  • fields=updated_time (to keep the query fast and the payload small)
  • limit=5000 (or some similarly large page size, as I'm only grabbing one field)

I then evaluate each post that has an updated_time greater than the would-be since date, and throw those posts into a queue to download the entirety of the post content.

So, for example, if the until (and, thus, since) date is 2015-07-07 but the updated_time on an individual post is 2015-10-15, then I know that post was created prior to 2015-07-07 but updated afterwards. It won't get picked up in a since query, but I can easily download it individually to synchronize my cache.

Note: If you're dealing with content where there are frequent updates on past content, you'd likely want to use the Graph API's Batch Requests feature, as opposed to downloading each post individually.

like image 148
Jeremy Caney Avatar answered Oct 20 '22 13:10

Jeremy Caney


If the aim of your application is to react to changes on a given page or feed, consider using Webhooks instead of manually crawling the page for updates.

Webhooks allows you to receive real-time HTTP notifications of changes to specific objects in the Facebook Social Graph.

like image 37
panepeter Avatar answered Oct 20 '22 13:10

panepeter