Here is the screenshot from postman for active entities,
However, I have access to the Ads account as shown here.
My App ID is 19136003. Any help would be appreciated. Thank you!
In general, these issues could be due to missing or incorrect authentication credentials. It could also be an issue with the signature due to reserved characters not being properly encoded. More information here.
That being said, weâve heard of issues with Postman. See this GitHub issue or search the forums for more information.
The active entities in the postman URL appears to be incorrect - it should have /stats in the path. The error message shouldnât return a 401 so is misleading. Could you provide the exact API request and post the response headers here?
Hi @osowskit1, @juanshishido, the issue is with getting stats, I tried the following, and still getting an unauthorized request.
Provided the start_time and end_time to be expressed in ISO8601. Example: 2017-05-19T07:00:00Z .Here is my code snippet,. I use the same code for campaigns, lineitems and active entities and they all work great except for the stats.
- Is the order of the params alphabetical too? As I have them sorted alphabetically before genrating the signature.
- What should the encoded start_time and end_time look like before generating the signature?
eg: end_time=2020-11-26T00%3A00%3A00Z
Requested URL:
https://ads-api.twitter.com/8/stats/accounts/knz4a?end_time=2020-11-26&entity_ids=hllds&entity=LINE_ITEM&granularity=DAY&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2020-11-25
We strongly recommend using an existing library that generates OAuth 1.0a authentication headers. The following pages can help you determine how to make authenticated requests and create a signature.
In most cases, Postman is able to create authenticated requests as well as Twurl. Many developers inspect the headers generated by either of these tools to help determine how to generate the appropriate headers.
Hi @osowskit1, I have tried the requests in Twurl and here are the header and URL campared to the ones generated by my code. Twurl works my code does not, and its only the stats api call which fails with unauthorized.
Twurl URL:
âGET /8/stats/accounts/{{accountid}}?end_time=2020-11-26T01%3A00%3A00Z&entity_ids=hllds&entity=LINE_ITEM&granularity=DAY&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2020-11-25T01%3A00%3A00Zâ
OAuth header from trace
âOAuth oauth_consumer_key=â{{consumerkey}}", oauth_nonce=âWWbGReO9Zrqygjq6BGdGDtHANvWu9L3bYYl7eXBU4â, oauth_signature=âx9iL%2Fbj%2FbCCRL4gNKpAnnHmSU8I%3Dâ, oauth_signature_method=âHMAC-SHA1â, oauth_timestamp=â1606921744â, oauth_token="{{token}}", oauth_version=â1.0"â
Code Generated URL:
âhttps://ads-api.twitter.com/8/stats/accounts/{{accountid}}?end_time=2020-11-26T01%3A00%3A00Z&entity_ids=hllds&entity=LINE_ITEM&granularity=DAY&metric_groups=ENGAGEMENT&placement=ALL_ON_TWITTER&start_time=2020-11-25T01%3A00%3A00Zâ
Code generated OAuth header
âOAuth oauth_consumer_key=â{{consumerkey}}", oauth_nonce=âf6252258ac2c4a50b356ba371e0d8fd0â, oauth_signature_method=âHMAC-SHA1â, oauth_signature=âTLD44d1XhkF5t60hRL3c9R1AaCw%3Dâ, oauth_timestamp=â1606921081â, oauth_token="{{token}}", oauth_version=â1.0"â
I dont see any difference expect for the obvious ones, like timestamp, nonce, signature. Does the order of the params in the header matter. I have them sorted alphabetically.
Any help is really appreciated.
@osowskit1, here is the response I get through code with the error.
{StatusCode: 401, ReasonPhrase: âAuthorization Requiredâ, Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
{
Cache-Control: no-store, no-cache, max-age=0
Date: Wed, 02 Dec 2020 14:58:04 GMT
Set-Cookie: personalization_id=âv1_ACxAXKgWwoLta4Lecka+tA==â; Max-Age=63072000; Expires=Fri, 02 Dec 2022 14:58:04 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
Set-Cookie: guest_id=v1%3A160692108445306236; Max-Age=63072000; Expires=Fri, 02 Dec 2022 14:58:04 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None
Server: tsa_b
strict-transport-security: max-age=631138519
x-api-version: 8.0
x-connection-hash: 7268b245caf41053a83d2c4cc3fc0e53
x-content-type-options: nosniff
x-current-api-version: 8.0
x-frame-options: SAMEORIGIN
x-response-time: 11
x-runtime: 5.3E-5
x-transaction: 00d5b4010012b824
x-xss-protection: 0
Content-Length: 122
content-disposition: attachment; filename=json.json
Content-Type: application/json; charset=utf-8
}}
â{âerrorsâ:[{âcodeâ:âUNAUTHORIZED_ACCESSâ,âmessageâ:âThis request is not properly authenticatedâ}],ârequestâ:{âparamsâ:{}}}â
@juanshishido and @osowskit1, just to make sure my oauth signature code is working as expected, I updated the params in my code to match the ones mentioned in the API documentation.
And I was successfully able to produce the following signature. (
This means my code works)
But when I follow the authorization documentation (https://developer.twitter.com/en/docs/authentication/oauth-1-0a/authorizing-a-request), I notice that the params are same but the signature shown here is not what is generated, and does not match the signature present on the signature creation documentation page.
How ever the params are same. Not sure how to produce this signature. Please explain.
Thank you!
@osowskit1, @carmenjyuen, @juanshishido
I am really stuck with Stats endpoint. All other endpoints for campaigns, line_items, activeentities work perfectly.
Appreciate your help. Thank you!
Could you verify that the request succeeds using Twurl. If so, you can use the -T option to print the authentication headers and use this to help modify your source to generate the same signature.
I would also consider using an open source library for HTTP requests that supports OAuth 1.0a as this is very tricky to implement.
@osowskit1, Thank you for the help. I was able to tweak my code to update the signature logic and generate the same signature as Twurl.
One difference I see between the following is, campaigns, line_items and active entities work when the time is specified like 2020-11-26T05:00:00Z. But, stats request works only when the time is specified like 2020-11-26.
1 Like
hello ,
iâm having a trouble when creating a function to make the card using twitter adds âŚalways it returns me {âerrorsâ:[{âcodeâ:âUNAUTHORIZED_ACCESSâ,âmessageâ:âThis request is not properly authenticatedâ}],ârequestâ:{âparamsâ:{}}}
this is the code of the function :
Hello I receive a 401 and this error message, can someone please tell me what itâs about? On my side it seems all good. Iâm trying to use the Ads API. Iâm using appscript and I can retrive the token but when I run the function to get the account info I get the error
{ errors:
[ { code: 'UNAUTHORIZED_ACCESS',
message: 'This request is not properly authenticated' } ],
request: { params: {} } }```
@juanshishido, @osowskit1 itâs possible to help me with my question? Thank you.
Iâd recommend opening a new thread to track these questions separately and including the API request URL and query parameters. We strongly recommend developers use libraries that support generating OAuth 1.0a headers for your language rather than trying to build this out. I would also suggest trying the same request using Twurl to verify the request is valid.