Facebook graph SINCE and UNTIL not working - facebook

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).

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

when i put a find query in mongodb without limit and the data of total row was exceeded from 16mb an exception shows up

I have a scenario where i need all document form the collection and do some calculation and show the analyze graph to the user.
At that point when I use the find function it shows me the error ( document fragment is too large: 24331229, max: 16777216 ).
in one collection document like 100000 and above.
My current scenario
I have 3 collection with 3 type of analyze representation.
visit_data (User visit the page and fill some forms having questions.)
graph_data (The graph represent the how many question answered and whats the response of the user )
tabular_data (Its shows the question and answer of the selected questions visited by the user.)
Like google analytic graph representation of the analysis of the websites by
--> date
--> Location
--> language
--> etc.
similarly I have some filters (date,user,location) for the above type of analyze result.
So on the above collection every day 50,000 documents are interested.
If we do 7 day filter or 30 day filter at that moment the total document was >1,00,000 and the size is >16mb.
When I use find() function it will give me that exception.
I am using php-mongo to get the values.
Is there any other solution to do this stuff?
Please Help me.

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.

get number of updates since a timestamps in 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"