Not able to find out listed Fields from Ads API v1

ads
api

#1

I am looking for certain fields for reporting from Twitter API but not able to find it out from GET call to Ads-API v1. .

List of Fields

  1.  Engagement, 
    
  2.  Impression
    
  3.  Retweets  
    
  4.  Replies
    
  5.  Click
    
  6.  Videos
    
  7.  Favorites
    

I am fetching the data at Campaign level. Can some help me to understand are these fields we can directly get from Twitter API call, if yes the please provide URL or theses are the calculated fields ? I am to fetch the Campaign level


#2

@macy_poc: Thanks for the question. Could you please share the request you’re making? This is most likely a metric_groups issue.


#3

@juanshishido I am able to the Data, but getting some other issues.
This is my Get Call to API,
stats_campaign.request <- GET(sprintf(“https://ads-
api.twitter.com/1/stats/accounts/%s”,credentials$ACCOUNT_ID),
query = list(
entity = “CAMPAIGN”,
entity_ids = paste(campaign.ids, collapse = “,”),
start_time = TWO.DAYS.AGO.ISO.8601.CHARACTER,
end_time = YESTERDAY.ISO.8601.CHARACTER,
granularity = “DAY”,
metric_groups = “ENGAGEMENT”,“BILLING”,
placement = “ALL_ON_TWITTER”),
accept_json(),
config(token = twitter_token))

And I am getting below Error - “Error: All components of query must be named”.

Also not able to fetch the data for granularity = “DAY”, fall into below error, " “Expect time to be midnight in the account’s local timezone for day granularity”.

$request$params$start_time
[1] “2016-11-07T04:00:00Z”

$request$params$end_time
[1] “2016-11-08T04:00:00Z”

Any help ???


#4

@macy_poc: Haven’t seen that error before. Are you using the twitter-php-ads-sdk? Have you made successful calls to the stats endpoint before?

It looks like you got closer seeing the INVALID_TIME_WINDOW error. For that, please note that the "start_time must be midnight in the account’s timezone, relative to UTC" (source). If you omit the timestamp, it will automatically be translated to the correct UTC value.


#5

@juanshishido Hi, I am using R Script. When I am making call to Stats at Account level, worked fine. Below is my call,
stats.request <- GET(sprintf(“https://ads-api.twitter.com/1/stats/accounts/%s”,credentials$ACCOUNT_ID),
query = list(
entity = “ACCOUNT”,
start_time = TWO.DAYS.AGO.ISO.8601.CHARACTER,
end_time = YESTERDAY.ISO.8601.CHARACTER,
granularity = “TOTAL”,
metric_groups = “ENGAGEMENT”,“BILLING”,
placement = “ALL_ON_TWITTER”),
accept_json(),
config(token = twitter_token)) .

Instead of this I want to fetch the data at Campaign_Id level. i.e Impression/retweets for each Campaign_Id and granularity = “DAY”.

Regarding to granularity = “DAY”, - I am using EST time same as Account’s time Zone.
TODAY <- Sys.Date() --> 2016-11-10
TODAY.ISO.8601 <- format_iso_8601(TODAY) --> 2016-11-10T00:00:00+00:00
TODAY.ISO.8601.CHARACTER <- gsub("\+00:00","-04:00Z", as.character(TODAY.ISO.8601)) -->
2016-11-10T00:00:00-04:00Z

Grtting Below Error ::
Error: Bad Request (HTTP 400).

$errors[[1]]$code
[1] “INVALID_TIME_WINDOW”

$errors[[1]]$message
[1] "Expect time to be midnight in the account’s local timezone for day granularity


#6

@macy_poc: Thanks for the clarification and for providing the entity=ACCOUNT request—that’s helpful.

Before we identify what’s different between the account-level and campaign-level requests, let’s change the granularity for the campaign-level request to TOTAL so that we remove the INVALID_TIME_WINDOW error. (We’ll change this back to DAY once we make sure we can make a success campaign-level request to the stats endpoint.) Are you able to make a successful request with this change?

Previously you mentioned you were seeing an “All components of query must be named” error message. This is not an Ads API error message. Instead, it looks like it comes from Hadley Wickham’s httr package: https://github.com/hadley/httr/blob/master/R/url-query.r#L15. Are you able to get the full trace of the request? This might help determine what part of the request is incorrect.

Other than that, the only difference we notice is that the account-level request isn’t explicit about the entity_ids parameter, which is a valid way to make the request. In order words, the campaign-level request includes paste(campaign.ids, collapse = ","), which could be causing a problem.


#7

@juanshishido
Able to make successful call for below request.

stats_campaign.request <- GET(sprintf(“https://ads-api.twitter.com/1/stats/accounts/%s”,credentials$ACCOUNT_ID),
query = list(
entity = “CAMPAIGN”,
entity_ids = paste(campaign.ids, collapse = “,”),
start_time = YESTERDAY.ISO.8601.CHARACTER,
end_time = TODAY.ISO.8601.CHARACTER,
granularity = “TOTAL”,
metric_groups = “ENGAGEMENT”,
placement = “ALL_ON_TWITTER”),
accept_json(),
config(token = twitter_token))

“All components of query must be named” got resolved. Only granularity = “DAY”, issues is there.


#8

@macy_poc: Great.

I’m taking a closer look at your snippet you provided

TODAY <- Sys.Date() --> 2016-11-10
TODAY.ISO.8601 <- format_iso_8601(TODAY) --> 2016-11-10T00:00:00+00:00
TODAY.ISO.8601.CHARACTER <- gsub("\+00:00","-04:00Z", as.character(TODAY.ISO.8601)) --> 
2016-11-10T00:00:00-04:00Z

In your gsub() function, try replacing the -04:00Z with -05:00Z.


#9

@juanshishido

I tried -05:00Z as well as -03:00Z. None of them worked.


#10

@macy_poc: What’s the account ID that’s facing this issue?


#11

Account id = 18ce54dd6nd


#12

Thanks for providing that information, @macy_poc!

It turns out this account’s timezone is actually America/Los_Angeles:

$ twurl -H ads-api.twitter.com "/1/accounts/18ce54dd6nd" | jq
{
  "request": {
    "params": {
      "account_id": "18ce54dd6nd"
    }
  },
  "data_type": "account",
  "data": {
    "name": {name},
    "business_name": null,
    "timezone": "America/Los_Angeles",
    "timezone_switch_at": "2013-05-22T07:00:00Z",
    "id": "18ce54dd6nd",
    "created_at": "2016-08-03T20:05:17Z",
    "salt": {salt},
    "updated_at": "2016-11-10T20:30:11Z",
    "business_id": null,
    "approval_status": "ACCEPTED",
    "deleted": false
  }
}

So, the offset should be -08:00Z. Thus, the following request is successful (of course, since I don’t have an actual campaign ID, the data array is empty):

$ twurl -H ads-api.twitter.com "/1/stats/accounts/18ce54dd6nd?placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT&start_time=2016-11-07T00:00:00-08:00Z&end_time=2016-11-08T00:00:00-08:00Z&granularity=DAY&entity=CAMPAIGN&entity_ids=abc123" | jq
{
  "data_type": "stats",
  "time_series_length": 1,
  "data": [],
  "request": {
    "params": {
      "start_time": "2016-11-07T08:00:00Z",
      "segmentation_type": null,
      "entity_ids": [
        "abc123"
      ],
      "end_time": "2016-11-08T08:00:00Z",
      "country": null,
      "placement": "ALL_ON_TWITTER",
      "granularity": "DAY",
      "entity": "CAMPAIGN",
      "platform": null,
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  }
}

Also works with time in the following format: 2016-11-07T08:00:00Z.

If this resolved the issue, please consider marking the thread as solved.


#13

@juanshishido I hvae one more questions, Do you from which Ads API, I can get Total Media Views (Videos, Vines, GIFs and Images). In version ) it is coming from Metric Media as Media_Views. But I am not able to find it out from Version 1.


#14

@macy_poc: It should be using metric_groups=MEDIA. Please take a look at our Metrics and Segmentation documentation.


#15

@juanshishido not able to find out Reach for each Campaign Id, below is my call

reach_campaign.request <- GET(sprintf(“https://ads-api.twitter.com/1/stats/accounts/%s/reach/”,credentials$ACCOUNT_ID),
query = list(
entity = “CAMPAIGN”,
entity_ids = paste(campaign.ids, collapse = “,”),
start_time = YESTERDAY.ISO.8601.CHARACTER,
end_time = TODAY.ISO.8601.CHARACTER,
granularity = “DAY”,
metric_groups = “ENGAGEMENT”,
placement = “ALL_ON_TWITTER”),
accept_json(),
config(token = twitter_token))

Error Message ::
Error: Not Found (HTTP 404).

reach_campaign.data <- content(reach_campaign.request)
print(reach_campaign.data)
$errors
$errors[[1]]
$errors[[1]]$code
[1] “ROUTE_NOT_FOUND”

$errors[[1]]$message
[1] “The requested resource could not be found”

$request
$request$params
named list()


#16

@macy_poc: To retrieve a summary of reach and average frequency, use the GET stats/accounts/:account_id/reach/campaigns endpoint. Note that this account feature requires whitelisting, which only an account manager can help you with.

See this post for an example request.


Reach and engagement
#17

@juanshishido I am making below call to get reach Data, but for reason not getting anything. What am I doing wrong, here ?? I have tried below combination to make a call,

 reach_campaign.request <- GET(sprintf("https://ads 
                                               api.twitter.com/1/stats/accounts/%s/reach/campaigns?start_time = 
                                               YESTERDAY.ISO.8601.CHARACTER& campaign_ids=5ygom& 
                                              end_time = TODAY.ISO.8601.CHARACTER,",credentials$ACCOUNT_ID),
                                            query = list( metric_groups = "ENGAGEMENT",
                                                             placement = "ALL_ON_TWITTER"),
                                                             accept_json(),
                                                             config(token = twitter_token))

     Fall into Below Error 
     $errors
     $errors[[1]]
     $errors[[1]]$code
    [1] "MISSING_PARAMETER"

    $errors[[1]]$message
    [1] "\"campaign_ids\" is a required parameter"

    $errors[[1]]$parameter
   [1] "campaign_ids"

   $errors[[2]]
   $errors[[2]]$code
   [1] "MISSING_PARAMETER"

   $errors[[2]]$message
   [1] "\"start_time\" is a required parameter"

   $errors[[2]]$parameter
   [1] "start_time" 

Also tried below call and fall into same error as above.

    reach_campaign.request <- GET(sprintf("https://ads-   
                           api.twitter.com/1/stats/accounts/%s/reach/",credentials$ACCOUNT_ID),
                            query = list(
                              entity = "CAMPAIGN", 
                              entity_ids = paste(campaign.ids, collapse = ","),
                              start_time = YESTERDAY.ISO.8601.CHARACTER,
                              end_time = TODAY.ISO.8601.CHARACTER,
                              granularity = "DAY",
                              metric_groups = "ENGAGEMENT",
                              placement = "ALL_ON_TWITTER"),
                            accept_json(),
                            config(token = twitter_token))

Any help, will be highly appreciated.

Thanks.


#18

@macy_poc: In your first request, there are spaces in the resource URL. For example: start_time = YESTERDAY... and & campaign_ids=.

Not sure about the second.


#19

@juanshishido I tried with that, didn’t work.

     reach_campaign.request <- GET(sprintf("https://ads 
                                             api.twitter.com/1/stats/accounts/%s/reach/campaigns?start_time=2016-
                                             11-14T00:00:00-08:00Z?campaign_ids=5ygom&end_time=2016-11-
                                              15T00:00:00-08:00Z",credentials$ACCOUNT_ID),
                            query = list(
                              #entity = "CAMPAIGN", 
                              #entity_ids = paste(campaign.ids, collapse = ","),
                              # start_time = YESTERDAY.ISO.8601.CHARACTER,
                              # end_time = TODAY.ISO.8601.CHARACTER,
                              granularity = "DAY",
                              metric_groups = "ENGAGEMENT",
                              placement = "ALL_ON_TWITTER"),
                            accept_json(),
                            config(token = twitter_token)) 

Fall into below error,

         $errors
          $errors[[1]]
          $errors[[1]]$code
         [1] "MISSING_PARAMETER"

          $errors[[1]]$message
          [1] "\"campaign_ids\" is a required parameter"

         $errors[[1]]$parameter
        [1] "campaign_ids"



      $request
      $request$params
      $request$params$start_time
     [1] "2016-11-14T08:00:00Z"

     $request$params$end_time
    [1] "2016-11-15T08:00:00Z"

    $request$params$account_id
   [1] "18ce54dd6nd"

'
Following below link as an Example.


#20

@macy_poc: You now have a question mark (?) before campaign_ids instead of an ampersand (&).