Error 401 Authorization Required, "UNAUTHORIZED_ACCESS"

oauth
api

#1

Hey,
I followed following steps:
1, I created a Twitter App.
2. Then, I got my App Id, Client ID, Client Secret, Access Toke, Access token secret .
3. Then, I got my App Id whitelisted by twitter.
4. Then, I tried using following Ads Api:
a. “https://ads-api.twitter.com/4/accounts/account_Id/app_lists
b. https://ads-api.twitter.com/4/accounts/account_Id/account_media
c. https://ads-api.twitter.com/4/accounts/account_Id/auction_insights
d. https://ads-api.twitter.com/4/accounts/ account_Id/recommendations
e. https://ads-api.twitter.com/4/accounts?account_ids=account_Id
using my account_Id as Account Id associated with my account.
5. Still I am getting " 401 Authorization Required " with response: {
“errors”: [{
“code”: “UNAUTHORIZED_ACCESS”,
“message”: “This request is not properly authenticated”
}],
“request”: {
“params”: {}
}}

Why this error is coming, whether I am missing something or there is any change in steps to use Api endpoints?
Please help me to get over this error.


#2

Hi @snigdhaJogdand ,

That 401 error most likely means your authorization token is incorrect. Can you try using twurl and see if you still get 401?

Best,
Shohei


#3

Hey,
I used OAuth 1 mechanism to use Ads API, using client Id, client secret, access token, access token secret and used App ID that is got whitelisted by Twitter.
I am getting 401 error.
Is there any “authentication token” required?
If yes, can you please help me with how and when to use it while using Ads API.
Thank You.


#4

Can you send me any documentation link to understand how to get authentication token and where & how to use Authentication token for Ads API.
Thank you


#5

Hi @snigdhaJogdand ,

Sorry, I meant token in general. I recommend you reading this guide:

There are several steps you need to follow in order to make a valid Authorization HTTP request header (I’m assuming you’re following this with your script/application you wrote). Could you please make sure you’re not missing any pieces there? such as “Building the header string” section on that page (escaping stuff).

Best,
Shohei


REST API return 401 (unauthorized access) error when trying to GET tweet preview
#6

I used OAuth ! Authorization while using Ads Api.
still getting the same error.
please help me out with this.

Thanks.


#7

@snigdhaJogdand

It’s difficult to debug without knowing your code. Are you using any third-party libraries?
https://developer.twitter.com/en/docs/basics/authentication/guides/single-user

Best,
Shohei


#8

No.
I am calling Ads API using postman.
API: https://ads-api.twitter.com/4/accounts/account_id/account_media
Authorization Machanism: OAuth 1 with Client Id, Client secret, Access toke, Access token Secret.
API documentation I refered is: https://developer.twitter.com/en/docs/ads/general/guides/getting-started

That all what I am doing.
Is any other thing required to access Api for whitelisted account.

Thanks.


#10

@snigdhaJogdand (Sorry I removed my previous answer as I misunderstood what’s the issue)

Anyway, I was able to call API via Postman with basic OAuth1.0 setup. You may want to check your ADVANCED setting area. Default settings worked for me though.

Also, you should select “Request Headers” for Add authorization data to setting:

If it doesn’t help, please double check that you’re using correct key and secret there. Again, but we highly recommend using twurl as it’s our official tool and easy to debug&help questions like this.

Best,
Shohei


#11

Hey! Did you get this figured out?! I am running into the same problem.

Thanks!


#12

Yes, actually I missed to use option, “Add Authorization data to” : “Request Headers” .
Then, preview request and see if the Aauth token is added to your headers.