'Unable to Request from Twitter Ads Api using OAuth in Python
I am stuck on a issue with Twitter-ads-api. I have completed the authorization and got the oauth-verifier token, but after this I am stuck on how to request for Ads data from their URL endpoint. Here is my code after getting the verifier:
consumer = oauth.Consumer(consumer_key, consumer_secret)
token = oauth.Token(data[0], data[1])
token.set_verifier(oauth_verifier)
client = oauth.Client(consumer, token)
# access_token_url
resp, content = client.request(f"https://ads-api.twitter.com/11/stats/accounts/{get_account_id()}/active_entities", "GET", body={"end_time":"2022-03-07", "entity":'LINE_ITEM',"start_time":"2022-03-01"})
print('Error ',content)
if resp['status'] != '200':
error_message = "Invalid response from Twitter API GET users/show: {status}".format(
status=resp['status'])
print(error_message)
return error_message
access_token = dict(urllib.parse.parse_qsl(content))
It has successfully giving response by the account name, this means that authorization is complete but how can I request other endpoints? It is giving me error:
b'{"errors":[{"code":"UNAUTHORIZED_ACCESS","message":"This request is not properly authenticated"}],"request":{"params":{}}}'
Invalid response from Twitter API GET users/show: 401
I know there is problem with my code. If anyone has this knowledge about it?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|