Are start/end times needed to query Ads API stats? (how to adjust for daylight savings time)

StackOverflow https://stackoverflow.com/questions/14822375

Question

I’m attempting to query Ad Group stats API for an Account for a full day’s worth of data.

The Facebook documentation recommendation is to specify start and end dates along with times (in UTC) as relates to the ad_account time zone, as in the following examples:

1) Pacific Time (12/8/2012):

/adgroupstats?start_time=2012-12-08T08:00:00&end_time=2012-12-09T08:00:00&
stats_mode=with_delivery&include_deleted=true&access_token=

2) Daylight savings (8/8/2012):

/adgroupstats?start_time=2012-08-08T07:00:00&end_time=2012-08-09T07:00:00
&stats_mode=with_delivery&include_deleted=true&access_token=

I'm looking for a better way to account for daylight savings time, so I'd like to know if excluding the time entirely is an option, since I'm just after the full day.

In testing, I've found the following to return the same results as option 2, but I'm wondering if this is a reliable method, since it is undocumented:

/adgroupstats?start_time=2012-08-08T00:00:00&end_time=2012-08-09T00:00:00&
stats_mode=with_delivery&include_deleted=true&access_token=
Était-ce utile?

La solution 2

So to answer my own question - leaving off the timestamp portion is no longer working after the latest FB API update...

As a work around for the daylight savings time issue - in my code I call out to the /stats api for a single day (making start and end dates the same and leaving off the time portion):

/stats?start_time=2012-08-01T00:00:00&end_time=2012-08-01T00:00:00

I retrieve the results of this call and look at the times Facebook returned to determine if FB adjusted this query for the Clients daylight savings time.

FB return: "start_time": "2012-07-31T07:00:00+0000",

Then I can query the /adgroupstats api with the correct times:

/adgroupstats?start_time=2012-08-01T07:00:00&end_time=2012-08-02T07:00:00

Note: /adgroupstats api does not seem to return the FB adjusted start time so I used /stats api as a work around

Autres conseils

You MUST provide start and end time. Otherwise there wouldn't be any way to know which day's stats that you want.

Refer to the "Querying Unique Stats" of the Stats Documentation.

And I quote "Note: As times are expressed in UTC you must manually adjust for daylight savings time in your request"

Hence the solution should be how to program your request to have DST adjusted start/end times.

If you're using PHP, refer to this: How can I detect day light savings automatically in PHP?

or: PHP daylight saving time detection

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top