Not able to find out listed Fields from Ads API v1

ads
api

#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 (&).


#21

@macy_poc: Going forward, please use twurl. This thread has good information for getting started: Setting up Twurl.


#22

@Grupo_Develop @juanshishido @paramunithi Able to make below call using below request,

reach_campaign.request <- GET(sprintf("https://ads- 
                        api.twitter.com/1/stats/accounts/18ce54dd6nd/reach/campaigns?start_time=2016-11-14T00:00:00-
                        08:00Z&campaign_ids=6gy9x&end_time=2016-11-15T00:00:00-08:00Z"),
                          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))

Able to make call, this is only for a one campaign ID, if I have more than 50 Campaign then I have to make a 50 call to API, and 50 times writer into file. Does’t seen to be a good approach. Is there any alternate way …???

Another Question is base on limitation of “A maximum of 20 items can be provided for entity_ids” . Can you please suggest better approach to call APIs, considering we have more than 100 Campaigns.

Thanks


#23

@Grupo_Develop @juanshishido @paramunithi How to get Start_time and End_Time for API call ? What I mean here, if I am fetching a Data for a day from 11-16-2016 to 11-17-2016, where can I find this information in Response. For now I am not getting any info. Though within data object there are fields, Start_Time/End_Time but these are related to Campaign’s creation. Not based on API call.

{"request":{"params":{"account_id":["xxxxxxxx"]}},"data"[],"data_type":["campaign"],"total_count":[25],"next_cursor":   
 {}}  

Any help…??

Thanks


#24

@juanshishido @nepokryty @Rihanna_NavyG4L @paramunithi @Grupo_Develop - Any update on last questions ?

Quick response highly appreciated.

Thanks


#25

@macy_poc: Please see the example requests and responses, below.

GET /1/stats/accounts/:account_id

$ twurl -H ads-api.twitter.com "/1/stats/accounts/18ce54d4x5t?entity=LINE_ITEM&entity_ids=6vn5g&start_time=2016-11-24&end_time=2016-11-26&granularity=DAY&placement=ALL_ON_TWITTER&metric_groups=ENGAGEMENT" | jq
{
  "data_type": "stats",
  "time_series_length": 2,
  "data": [
    {
      "id": "6vn5g",
      "id_data": [
        {
          "segment": null,
          "metrics": {
            "impressions": [
              0,
              68
            ],
            "tweets_send": null,
            "qualified_impressions": null,
            "follows": null,
            "app_clicks": null,
            "retweets": null,
            "likes": [
              0,
              1
            ],
            "engagements": [
              0,
              14
            ],
            "clicks": [
              0,
              4
            ],
            "card_engagements": null,
            "replies": null,
            "url_clicks": null,
            "carousel_swipes": null
          }
        }
      ]
    }
  ],
  "request": {
    "params": {
      "start_time": "2016-11-24T08:00:00Z",
      "segmentation_type": null,
      "entity_ids": [
        "6vn5g"
      ],
      "end_time": "2016-11-26T08:00:00Z",
      "country": null,
      "placement": "ALL_ON_TWITTER",
      "granularity": "DAY",
      "entity": "LINE_ITEM",
      "platform": null,
      "metric_groups": [
        "ENGAGEMENT"
      ]
    }
  }
}

GET stats/accounts/:account_id/reach/campaigns

$ twurl -H ads-api.twitter.com "/1/stats/accounts/18ce54d4x5t/reach/campaigns?campaign_ids=6l0nl&start_time=2016-11-24&end_time=2016-11-26" | jq
{
  "request": {
    "params": {
      "campaign_ids": [
        "6l0nl"
      ],
      "start_time": "2016-11-24T00:00:00Z",
      "end_time": "2016-11-26T00:00:00Z",
      "account_id": "18ce54d4x5t"
    }
  },
  "data_type": "reach",
  "data": [
    {
      "id": "6l0nl",
      "total_audience_reach": 68,
      "average_frequency": 1
    }
  ]
}

In both cases, you can find the start and end times in request.params.start_time and request.params.end_time, respectively. That being said, you will have this information prior to seeing the response, because you would have had to pass in those values.


#26

Hi @macy_poc,

I was wondering whether you could share the whole R code on how to accessing campaign data, so AUTHORIZATION code etc, I am struggling with getting R access, you can easily access the public data through available packages like TwitteR and RTweet, but I struggle to get properly authenticated for access to our paid campaigns data.

Thanks for your support,

Thanks,
Wojciech