I have set up a new app in a project, using the Essential service level. I have reset the access tokens a few times but the problem keeps re-ocurring. There is no indication that my app has not been approved but I am not being authorised with the base settings. Have activated Auth 1 I have provided a snippet below along with the response. New to the api, any assistance much appreciated!
import tweepy
import os
from key import apiKey, apiKeySecret, accessToken, accessTokenSecret, bearerToken
auth = tweepy.OAuth1UserHandler(
apiKey, apiKeySecret, accessToken, accessTokenSecret
)
api = tweepy.API(auth)
print(api.verify_credentials().screen_name)
Unauthorized: 401 Unauthorized
89 - Invalid or expired token.
This is calling the v1.1 API, which requires Elevated Access, while you have Essential Access, which gives you only v2 API. To use it, use Client in Tweepy, not API Client — tweepy 4.10.1 documentation
Thank you Igor,
I did try using Client as well, both with a bearerToken and using my api key and access tokens. However it also gave an Unauthorized error, this time with less detail. Snippet below:
import tweepy
import os
os.chdir(‘…’)
from key import apiKey, apiKeySecret, accessToken, accessTokenSecret, bearerToken
client = tweepy.Client(
apiKey, apiKeySecret, accessToken, accessTokenSecret
)
client = tweepy.Client(bearer_token=‘bearerToken’)
client.get_user(username=‘jack’)
Unauthorized: 401 Unauthorized
Unauthorized
Is this exactly what’s in the code? Because this would make the bearer token equal to the string bearerToken, not the value of bearerToken assuming the from key import… loads it correctly.
(obviously don’t share your token here on the forum, but it’s worth double checking in a python debugger to make sure that the variable is definitely loaded correctly)