Create Campaign 401 UNAUTHORIZED_ACCESS

oauth
token
ads
campaign-management

#1

Hi Twitter Team.
We’re currently developing and testing a feature that create campaigns with Twitter Ads API.
We’re already got AD_MANAGER and TWEET_COMPOSER permission.

{
  "data_type": "user_access",
  "data": {
    "user_id": xxxxxxx,
    "permissions": [
      "AD_MANAGER",
      "TWEET_COMPOSER"
    ]
  },
  "request": {
    "params": {
      "account_id": "xxxxxxx"
    }
  }
}

Now I can get user’s campaigns.like this

{
  "request": {
    "params": {
      "account_id": "some account id"
    }
  },
  "data": [
    {
      "name": "My Campaign",
      "start_time": "2017-06-08T08:32:00Z",
      "reasons_not_servable": [],
      "servable": true,
      "daily_budget_amount_local_micro": 1000000,
      "end_time": null,
      "funding_instrument_id": "xxxx",
      "duration_in_days": null,
      "standard_delivery": true,
      "total_budget_amount_local_micro": 1000000,
      "id": "xxxxx",
      "entity_status": "ACTIVE",
      "paused": false,
      "account_id": "some account id",
      "frequency_cap": null,
      "currency": "JPY",
      "created_at": "2017-06-08T08:31:08Z",
      "updated_at": "2017-06-08T08:32:49Z",
      "deleted": false
    }
  ],
  "data_type": "campaign",
  "total_count": 1,
  "next_cursor": null
}

but when I create campaign I got

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

PS : line items is creatable
Our app id is 13836879

Thanks.


キャンペーンの作成ができない
#2

Hi @neplove,

Thanks for reaching out! Would you be able to provide the full request you’re making for successfully creating line items and unsuccessfully creating campaigns? If you use twurl you can pass in the -t parameter for a full trace (please be sure to redact/remove your keys when you reply to this post). That should give us the information we need to figure out what might be happening.


#3

Hi @brooklynmike.
we used oauth2 library.
this is my request.

request with oauth2.oauth

consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(oauth_token, oauth_token_secret)
client = oauth.Client(consumer, token)
client.request(endpoint, “POST”)

Create Campaign

get funding_instrument_id with GET accounts/:account_id/funding_instruments api
querystring
funding_instrument_id=xxxx&total_budget_amount_local_micro=1000000&daily_budget_amount_local_micro=1000000&start_time=2017-08-01T00:00:01Z&end_time=2018-01-01T00:05:00Z&paused=true&name=FromBzspApi00001
{
  "status": "401",
  "x-api-version": "1.0",
  "content-length": "122",
  "x-xss-protection": "1; mode=block",
  "x-content-type-options": "nosniff",
  "content-disposition": "attachment; filename=json.json",
  "transfer-encoding": "chunked",
  "set-cookie": "guest_id=v1%3A149708235258290687; Domain=.twitter.com; Path=/; Expires=Mon, 10-Jun-2019 08:12:32 UTC",
  "strict-transport-security": "max-age=631138519",
  "x-tsa-request-body-time": "0",
  "server": "tsa_m",
  "x-connection-hash": "c2fa976d3c5571f28e465cc3b02a895d",
  "x-runtime": "4.7E-5",
  "-content-encoding": "gzip",
  "date": "Sat, 10 Jun 2017 08:12:32 GMT",
  "x-transaction": "00bc143a00b8c9b0",
  "x-frame-options": "SAMEORIGIN",
  "x-response-time": "106",
  "content-type": "application/json;charset=utf-8"
}

Create Line Items

before this request,we created campaign in campaign manager console.
querystring
campaign_id=xxxx&name=Testbzsp001&product_type=PROMOTED_TWEETS&placements=TWITTER_TIMELINE&paused=true&bid_amount_local_micro=1000000&objective=WEBSITE_CLICKS
{
  "x-api-version": "1.0",
  "content-length": "1045",
  "x-tsa-request-body-time": "1",
  "x-rate-limit-reset": "1497082412",
  "x-rate-limit-remaining": "299",
  "x-xss-protection": "1; mode=block",
  "x-content-type-options": "nosniff",
  "x-connection-hash": "c2fa976d3c5571f28e465cc3b02a895d",
  "x-runtime": "0.090079",
  "status": "201",
  "content-disposition": "attachment; filename=json.json",
  "transfer-encoding": "chunked",
  "set-cookie": "guest_id=v1%3A149708235270745841; Domain=.twitter.com; Path=/; Expires=Mon, 10-Jun-2019 08:12:32 UTC",
  "x-access-level": "read-write",
  "-content-encoding": "gzip",
  "date": "Sat, 10 Jun 2017 08:12:32 GMT",
  "x-rate-limit-limit": "300",
  "x-response-time": "197",
  "x-transaction": "00e6232c0024d823",
  "strict-transport-security": "max-age=631138519",
  "server": "tsa_m",
  "x-frame-options": "SAMEORIGIN",
  "content-type": "application/json;charset=utf-8"
}

and successed.

thanks.


#4

when we change request library from oauth2 to requests_oauthlib this problem was solved.
close this issue please.
Thanks.


#5