Twitter Ada Api access error for Stats related endpoint

api

#1

Our Application ID :- 13481082
Recently we got access for Ads Api and we can access below endpoints.

https://ads-api.twitter.com/1/accounts/awj1s/line_items
https://ads-api.twitter.com/1/insights/accounts/awj1s?audience_type=ALL_ON_TWITTER

But while trying any of the Stats related endpoints . Getting Access error.

HttpResponse getstatsdata = twitterAdsInstance.getTwitterAdsClient().get(“https://ads-api.twitter.com/1/stats/accounts/awj1s/reach/campaigns?campaign_ids=8jw3r&start_time=2016-11-01T07:00:00Z&end_time=2016-11-16T07:00:00Z”);
System.out.println(getdata4.asString());

Error :-

Exception in thread “main” 401:Authentication credentials (https://dev.twitter.com/pages/auth) were missing or incorrect. Ensure that you have set valid consumer key/secret, access token/secret, and the system clock is in sync.
{“errors”:[{“code”:“UNAUTHORIZED_ACCESS”,“message”:“This request is not properly authenticated”}],“request”:{“params”:{}}}

Relevant discussions can be found on the Internet at:
http://www.google.co.jp/search?q=855a0e23 or
http://www.google.co.jp/search?q=0059c573
TwitterException{exceptionCode=[855a0e23-0059c573], statusCode=401, message=This request is not properly authenticated, code=-1, retryAfter=-1, rateLimitStatus=null, version=4.0.4}
at twitter4j.HttpClientImpl.handleRequest(HttpClientImpl.java:164)
at twitter4j.HttpClientBase.request(HttpClientBase.java:57)
at twitter4j.HttpClientBase.get(HttpClientBase.java:75)
at twitter4j.TwitterAdsClient.get(TwitterAdsClient.java:195)
at test.Twitter.TryEndpoint.main(TryEndpoint.java:41)


#2

@ajay_api - Yes it does look like your app was granted access, however you need to go through user authentication for your app ID in order to make API requests. Please follow the getting started on this read page.


#3

Thanks for the reply.
Yes I have done the App authentication part and same reason am able to download Campaigns as well as Promoted tweets. But I can’t download any of the stats. So I was wondering if there is anything still need to be done from backend.

I am able to access below endpoints as well. But none of the stats so far. But in case you want me to check through twurl , I can do that as well. Please let me know the same.

https://ads-api.twitter.com/1/accounts/awj1s/line_items
https://ads-api.twitter.com/1/insights/accounts/awj1s?audience_type=ALL_ON_TWITTER


#4

@ajay_api: Please get set up with twurl as this makes debugging easier. Once you’ve got that working, please make the following requests and share the response you’re getting:

$ twurl -H ads-api.twitter.com "/1/accounts/awj1s/line_items?count=1"
$ twurl -H ads-api.twitter.com "/1/stats/accounts/awj1s/reach/campaigns?campaign_ids=8jw3r&start_time=2016-11-01T07:00:00Z&end_time=2016-11-16T07:00:00Z"
$ twurl -H ads-api.twitter.com "/1/stats/accounts/awj1s?entity=CAMPAIGN&entity_ids=8jw3r&start_time=2016-11-01T07:00:00Z&end_time=2016-11-07T07:00:00Z&placement=ALL_ON_TWITTER&granularity=TOTAL&metric_groups=ENGAGEMENT"

There is no reason why you should be able to make one of these and not the other.


Ads API 403 'Unauthorized Access"
#5

I have tried with twurl and it didn’t give any error . Please refer the output here.
But from Java it still gives the error and I can still query campaigns/promoted tweets/line items . Except Stats.

twurl -H ads-api.twitter.com “/1/accounts/awj1s/line_items?count=1”

{  
  "request":{  
    "params":{  
      "count":1,
      "account_id":"awj1s"
    }
  },
  "data":[  
    {  
      "bid_type":"MAX",
      "advertiser_user_id":18313840,
      "name":"Untitled",
      "placements":[  
        "TWITTER_SEARCH"
      ],
      "start_time":null,
      "bid_amount_local_micro":500000,
      "automatically_select_bid":false,
      "advertiser_domain":null,
      "target_cpa_local_micro":null,
      "primary_web_event_tag":null,
      "charge_by":"ENGAGEMENT",
      "product_type":"PROMOTED_TWEETS",
      "end_time":null,
      "bid_unit":"ENGAGEMENT",
      "total_budget_amount_local_micro":null,
      "objective":"CUSTOM",
      "id":"rix",
      "entity_status":"ACTIVE",
      "paused":false,
      "account_id":"awj1s",
      "optimization":"DEFAULT",
      "categories":[  

      ],
      "currency":"USD",
      "created_at":"2011-12-02T11:59:15Z",
      "tracking_tags":[  

      ],
      "updated_at":"2016-03-23T23:40:21Z",
      "include_sentiment":"POSITIVE_ONLY",
      "campaign_id":"ryf",
      "creative_source":"MANUAL",
      "deleted":false
    }
  ],
  "data_type":"line_item",
  "total_count":1709,
  "next_cursor":"18s97ym8"
}

twurl -H ads-api.twitter.com "/1/stats/accounts/awj1s/reach/campaigns?campaign_ids=8jw3r&start_time=2016-11-01T07Z"0:00Z&end_time=2016-11-16T07:00:00

{  
  "request":{  
    "params":{  
      "campaign_ids":[  
        "8jw3r"
      ],
      "start_time":"2016-11-01T07:00:00Z",
      "end_time":"2016-11-16T07:00:00Z",
      "account_id":"awj1s"
    }
  },
  "data_type":"reach",
  "data":[  
    {  
      "id":"8jw3r",
      "total_audience_reach":0,
      "average_frequency":null
    }
  ]
}

twurl -H ads-api.twitter.com “/1/stats/accounts/awj1s?entity=CAMPAIGN&entity_ids=8jplacement=ALL_ON_TWITTER&granularity=TOTAL&metric_groups=ENGAGEMENT”

{  
  "data_type":"stats",
  "time_series_length":1,
  "data":[  
    {  
      "id":"8jw3r",
      "id_data":[  
        {  
          "segment":null,
          "metrics":{  
            "impressions":null,
            "tweets_send":null,
            "qualified_impressions":null,
            "follows":null,
            "app_clicks":null,
            "retweets":null,
            "likes":null,
            "engagements":null,
            "clicks":null,
            "card_engagements":null,
            "poll_card_vote":null,
            "replies":null,
            "url_clicks":null,
            "carousel_swipes":null
          }
        }
      ]
    }
  ],
  "request":{  
    "params":{  
      "start_time":"2016-11-01T07:00:00Z",
      "segmentation_type":null,
      "entity_ids":[  
        "8jw3r"
      ],
      "end_time":"2016-11-07T07:00:00Z",
      "country":null,
      "placement":"ALL_ON_TWITTER",
      "granularity":"TOTAL",
      "entity":"CAMPAIGN",
      "platform":null,
      "metric_groups":[  
        "ENGAGEMENT"
      ]
    }
  }
}

#6

Thanks for confirming, @ajay_api. We can now rule out any access issues. In other words, your app ID has proper access to the Ads API. The issue seems to be with the OAuth implementation. You can visit the OAuth category for additional help.


#7

@ajay_api: As a follow up, please see this post for additional details.


#8

Thanks for the link. I will check the same.