0

I have a Twitter APP witch is granted access to Twitter Ads API.

If I use twurl or php curl, I can GET informations from the Ads API.

I am trying to run a POST in the sandbox API in order to create an account.

If I run the provided API trough twurl this is what I get:

twurl -t -H "ads-api-sandbox.twitter.com" "/5/accounts" | jq
opening connection to ads-api-sandbox.twitter.com:443...
opened
starting SSL for ads-api-sandbox.twitter.com:443...
SSL established
<- "GET /5/accounts HTTP/1.1\r\nAccept-Encoding:
...
read 79 bytes
Conn close
{
  "request": {
    "params": {}
  },
  "next_cursor": null,
  "data": []
}

This is a GET response. It shows nothing because there is no an account created in the sandbox.

If run with a php (Laravel 5.7) code this is what I GET:

{#712 ▼
  +"request": {#678 ▼
    +"params": {#627}
  }
  +"next_cursor": null
  +"data": []
}

If I run a POST from the same PHP,

{#678 ▼
  +"errors": array:1 [▼
    0 => {#627 ▼
      +"code": "UNAUTHORIZED_ACCESS"
      +"message": "This request is not properly authenticated"
    }
  ]
  +"request": {#714 ▼
    +"params": {#712}
  }
}

If I try to get informations from the production Ads Twitter API, I can see all the expected data.

That means that I do have access to the API, at least for GET, but I cant create an account in the sandbox OR I cant run a POST request.

I couldn't find any documentation showing how to solve this issue. Only this post without solution.

Any idea?

IgorAlves
  • 5,086
  • 10
  • 52
  • 83
  • It is likely an issue creating authorization headers. What library are you using to create authorization headers https://developer.twitter.com/en/docs/basics/authentication/guides/authorizing-a-request – osowskit May 04 '19 at 02:30
  • @osowskit this is the library I am using: https://github.com/J7mbo/twitter-api-php I have found it in this post https://stackoverflow.com/questions/12916539/simplest-php-example-for-retrieving-user-timeline-with-twitter-api-version-1-1/15314662#15314662 – IgorAlves May 06 '19 at 13:50
  • I'd recommend trying the POST request in Twurl yo verify the URL and credentials work. Could you include more PHP code without your keys – osowskit May 06 '19 at 14:08

0 Answers0