I’m still having the issue with the synchronous analytics endpoint, the actual solution for my issue is not in that post
I think the problem is with the oauth_signature
Here is my powershell code which is used to create oauth_signature(the oauth_signature generated by this code works fine with the other endpoints but not with analytics endpoint)
$baseurl = ‘https://ads-api.twitter.com/4/stats/accounts/18ce53zx1fm’
$signature = “GET&”;
$signature += [System.Uri]::EscapeDataString($baseurl) + “&”;
$signature += [System.Uri]::EscapeDataString(“oauth_consumer_key=” + $oauth_consumer_key + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_nonce=” + $oauth_nonce + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_signature_method=HMAC-SHA1&”);
$signature += [System.Uri]::EscapeDataString(“oauth_timestamp=” + $oauth_timestamp + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_token=” + $oauth_token + “&”);
$signature += [System.Uri]::EscapeDataString(“oauth_version=1.0”);
$signature_key = [System.Uri]::EscapeDataString($oauth_consumer_secret) + “&” + [System.Uri]::EscapeDataString($oauth_token_secret);
$hmacsha1 = new-object System.Security.Cryptography.HMACSHA1;
$hmacsha1.Key = [System.Text.Encoding]::ASCII.GetBytes($signature_key);
$oauth_signature = [System.Convert]::ToBase64String($hmacsha1.ComputeHash([System.Text.Encoding]::ASCII.GetBytes($signature)));
[System.Uri]::EscapeDataString($oauth_signature)
$Endpoint = ‘https://ads-api.twitter.com/4/stats/accounts/18ce53zx1fm?granularity=DAY&placement=ALL_ON_TWITTER&start_time=2018-11-26&end_time=2018-11-28&entity=CAMPAIGN&entity_ids=testxyz,testabc,&metric_groups=ENGAGEMENT,WEB_CONVERSION’
$response = Invoke-WebRequest -Uri $Endpoint -Headers @{‘AUTHORIZATION’=$oauth_authorization} -Method GET
I was able to make the request to the synchronous analytics endpoint successfully through POSTMAN but not through the script
The $oauth_signature generated by the above code, won’t match with the oauth signature generated by the POSTMAN for the same request and same credentails (i.e , timestamp, nonce,oauth_token,consumerkey etc everthing same)
Now the strange thing is that if I change the $baseurl and $Endpoint to “https://ads-api.twitter.com/4/accounts/18ce53zx1fm/campaigns” then it works fine($oauth_signature also generated by the script exactly matches with that of the oauth signature generated by POSTMAN)
Which is why I intially thought that there might be something wrong with the BASE URL but as you confirmed that BASE URL is correct, I’ve no idea why my oauth_signature generated by script is wrong and causing UNAUTHORIZED_ACCESS error
Please help me in finding out the root cause of this issue.