I am getting an 401 error when trying to pull from stats/accounts/:account_id/campaigns/:id while other endpoints such as accounts/:id are working as expected

oauth
ads

#1

Previously, our app had to be given specific access to the campaign endpoint. Having tested via curl and the oAuth tool it doesn’t seem like an issue with our process (specially since other endpoints are functioning).

Any pointers would be helpful.

Thanks.


#2

Sorry to hear you’re having issues, datayak.

A couple questions for debugging:

  1. Would you post the full API request you made and the full API
    response received?
  2. Is twurl also set up on the
    machine you’re making the request from?

#3

Yes, twurl is setup on my machine.

Here’s a sample request:

https://ads-api.twitter.com/0/stats/accounts/18ce53y02bf/campaigns/21mvd?start_time=2015-04-28T07:00:00&end_time=2015-05-04T07:00:00&granularity=DAY&metrics=promoted_tweet_timeline_impressions&segmentation_type=GENDER',

Headers: { Authorization: OAuth oauth_consumer_key="RnXQp7UxfVrHcsgW6rIawcN8T",oauth_nonce="3a3a985ep4i9akrf",oauth_signature="pd3D8mTLiGjdwegVBOWCgew2W8o%3D",oauth_signature_method="HMAC-SHA1",oauth_timestamp="1436207016",oauth_token="70769495-RPsj532pQSRTL7qj8znkdwqYuSChIq63jzIZkdZAR",oauth_version="1.0"

Here’s the response we get:

{
  "errors": [
    {
      "code": "UNAUTHORIZED_ACCESS",
      "message": "This request is not properly authenticated"
    }
  ],
  "request": {
    "params": {}
  }
}

#4

Would you check that the consumer key you are using to make the request is the same as the API key that was granted access to the Ads API?

This information can be found in your confirmation email for the whitelisted app ID.

If that matches, would you confirm that the default profile in your .twurlrc file is the one with correct consumer key?


#5

Yes @emmolam, the Api keys are for the same app that was granted access. The default account used it also the same app.


#6

We revisited how the OAuth tokens are generated and found that our spec-based implementation was different than that required by Twitter. We reworked it and with the new tokens, we’re able to make calls to the stat endpoint.

Thanks for your help @emmolam!


#7

Glad you guys have it sorted out @datayak! And thanks for letting us know.


#8