get number of updates since a timestamps in facebook - facebook

Can we get the number of updates since a particular timestamps using graph APIS? Number of updates might be number of new New feed or Messages.

depending on which api you are calling
When searching for public posts or posts on the user's News Feed, you
can page over the results by using the since, until and limit
parameters. since and until both accept a unix timestamp. When paging
back in time, you should use until in conjunction with limit where
until is the unixtime value of the created_time field in the last
object returned by your previous query. When paging forward in time
you should set since to be the unixtime value of the created_time
field in the first object returned by your previous query. Please
note, you can only search about 1 to 2 weeks back in the News Feed.
/me/feed?since=2+hours+ago&until=now "using strtotime in php"

Related

Facebook Marketing API Adset Filtering

I am using the Facebook Marketing API and making a call to get the adsets belonging to an adaccount (https://developers.facebook.com/docs/marketing-api/reference/ad-account/adsets/). My issue is that for one of my ad accounts, there are to many adsets available and as such the call is either taking long or has to many pages. Is there a way that i can possiblly add on date filtering to the request so that it will filter out all those adsets outside of the specified dates?
This is the request i am making with a dummy act id:
act_12345678?fields=account_id,name,currency,business{id},adsets{id,name,campaign{id,name,start_time,stop_time,spend_cap,status,insights.date_preset(lifetime){spend}},start_time,end_time,adset_schedule,billing_event,lifetime_budget,budget_remaining,daily_budget,lifetime_imps,status,configured_status,optimization_goal,is_autobid,insights.date_preset(lifetime).as(lifetime_insights){spend}, insights.time_range({'since':'1990-01-01', 'until':'2018-04-26'}).as(insights_to_date){spend}}
It appears that the "filtering" parameter works in this case.
For example, if you want to return all adsets that had a start time greater than 12/31/2017 and less than 01/31/2018, you can try the following.
Note that I had to first convert the start and end dates to a UNIX timestamp:
act_12345678/adsets?filtering=[{'field':'adset.start_time','operator':'GREATER_THAN','value':'1514678400'}, {'field':'adset.start_time','operator':'LESS_THAN','value':'1517356800'}]
You can add the "filtering" parameter to your request URL, and it should then filter both on the dates and the fields you specified.
To convert the dates to UNIX time stamp I used the following link: https://www.unixtimestamp.com/index.php

Facebook graph SINCE and UNTIL not working

When I get data from Facebook graph explore with query string
act_109418612584009/campaigns?fields=id,name,adsets{id,name,insights}&since=2016-03-07&until=2016-03-08
Result I get is full data (not range in since and until).
2016-03-17: Update
Wrong way, i had read document and solve it.
Find this at https://developers.facebook.com/docs/marketing-api/insights/v2.5
Struct of query is
https://graph.facebook.com/<API_VERSION>/<AD_OBJECT_ID>/insights
So meaning i can get data with query
https://graph.facebook.com/v2.5/6032185014626/insights?time_range={"since":"2015-03-01","until":"2015-03-31"}
6032185014626 is Id of adset
Happy coding
Have a look at
https://developers.facebook.com/docs/graph-api/using-graph-api#reading (chapter Time-based Pagination)
A time-paginated edge supports the following parameters:
until : A Unix timestamp or strtotime data value that points to the end of the range of time-based data.
since : A Unix timestamp or strtotime data value that points to the start of the range of time-based data.
limit : This is the number of individual objects that are returned in each page. A limit of 0 will return no results. Some edges have an upper maximum on the limit value, for performance reasons. We will return the correct pagination links if that happens.
next : The Graph API endpoint that will return the next page of data.
previous : The Graph API endpoint that will return the previous page of data.
You need to send unix timestamps instead of dates (YYYY-MM-DD).

Getting all Tweets from a User, after a certain date

You can get all tweets for a user: via the getUserTimeline() method.
You can also get all tweets after a specific date: sinceId() method.
But I want to combine these two. I want to get all tweets from a certain user, but only those tweets which were posted after a given date. Any ideas on how to do this?
I don't understand why you need sinceId(). getUserTimeline() returns a paginated list of Statuses. For each status in the list, doing status.getCreatedAt() returns a Date which is a Comparable. You can easily compare Date instances with each other and determine if a Date occured after another Date.
I wound up just using the id of the tweet, as a marker for the date. I didnt care about the date per se, but simply whether the tweet was before or after the previously loaded tweet. The docs suggest that the id is a more or less reliable indicator of recency. I.e., id 1234 is most likely to be a tweet that was posted before id 1233.
Thanks!

Get home feed of a particular user of a specific time stamp using graph API

I am trying to build a Facebook application by using Facebook Graph API. I am trying to get the home feed of the application user for a particular time span. e.g. From 11-02-2014 to 15-07-2014. I have used since and until in Facebook Graph Explorer but it returned news feed of two consecutive days.
2011-01-01 is the wrong synthax to represent a time on Facebook. You should use Unix timestamps: 1418971177.
A time-paginated edge supports the following parameters:
until : A Unix timestamp or strtotime data value that points to the end of the range of time-based data.
since : A Unix timestamp or strtotime data value that points to the start of the range of time-based data.
limit : This is the number of individual objects that are returned in each page. A limit of 0 will return no results. Some
edges have an upper maximum on the limit value, for performance
reasons. We will return the correct pagination links if that happens.
Source: https://developers.facebook.com/docs/graph-api/using-graph-api/v2.2#
So, instead of:
/me/home?since=2011-01-01&until=2011-05-05
You must use:
/me/home?limit=25&until=1418971177 with until.
Or:
/me/home?limit=25&since=1418971128 with since.
Note that you can't use since and until together. You have to use the limit field to restrict the amount of results you get.

Querying old links from public Facebook page returns an empty set

I am trying to fetch links that were posted on a public Facebook page sometime ago, in 2011 for example. Specifically, the Arabic CNN page on facebook: http://www.facebook.com/CNNArabic
Things I tried:
1- Graph API, a query like this:
CNNArabic/links?fields=id,name,link,created_time&limit=25&until=2012-05-15
2- FQL
SELECT link_id, url, created_time FROM link WHERE owner = 102581028206 and created_time < 1337085958 LIMIT 100
Both give an empty data set while there is data on the page on or before this date.
Other things I noticed:
1-If I changed the date to something like 2013-01-17 (which is yesterday), it works fine.
2-If I changed the date to something like 2012-12-17 (about a month ago), an empty data set is returned, however if I followed the next page links in the returned data set from the query in number 1 above until I pass by this date I actually get data.
I tried writing code that kept following the next page pointers until I reach the links on the date I want. However I need data much older (say in 2011) and the result set gets exhausted say 2 or 3 months earlier than now, in other words no more next links are returned so I actually can never reach that old data.
To cut this short:
is there a way I can query links that were posted on a public page before a specified date?
Querying the page's feed works in the Graph API:
/102581028206/feed?fields=id,link,name,created_time&limit=25&until=2012-05-15
This returns all the posts. There should be a way to filter this using field expansion, but I couldn't get the few things I tried to work.
You can get this filtered for links only with FQL on the stream table:
SELECT message, attachment, created_time FROM stream WHERE source_id = 102581028206
AND created_time < strtotime('2012-05-15') AND type=80 LIMIT 10
Links are type=80.