Authorization error 403 with Twitter API using python

61 Views Asked by At

I am using the Twitter API and I have a project that needs to collect tweets about COVID-19 on a specific date.

I get this error message during collection:

"error":{
  "message":"Forbidden: Authentication succeeded but account is not authorized to access this resource.",
  "sent":"xxxxxxxx",
  "transactionId":"xxxxxxxxxxxxxx"
}}',) 
(403): {"error":{"message":"Forbidden: Authentication succeeded but account is not authorized to access this resource.

I have a free 30-day sandbox so I did not pay for the premium because I am guessing there is no need? And I used it with the TwitterAPI library.

Here is the full code.

My Dev environment label: Sandbox

from TwitterAPI import TwitterAPI
from tqdm import tqdm
consumer_key = "xxxxx"
consumer_secret = "xxxxx"
access_token = "xxxxxxxxxxxxxx"
access_token_secret = "xxxxxx"
auth = tw.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
api = TwitterAPI(consumer_key, consumer_secret, access_token, access_token_secret)
r = api.request('tweets/search/30day/:Sandbox',
                {'query':'covid'}) 
tweets_copy = []
for tweet in tqdm(r):
    tweets_copy.append(tweet)
print(f"new tweets retrieved: {len(tweets_copy)}")

please I need your help I will appreciate any advice

Do you think if I upgrade to premium it will solve the problem?

0

There are 0 best solutions below