I have tried authenticating with both OAuth1.0 and OAuth2.0 (bearer token).
When I am using OAuth1.0 and can I can only use client.get_home_timeline() function, all other functions give me a 401 unauthorized error ( I’ve confirmed several times that all 4 my keys are correct and the home_timeline function gives me my home timeline).
When using the OAuth2.0 and make a request such as timeline = requests.request(method=‘Get’,url=my_url, params=id) I get exactly the same mistake.
I regenerated my tokens and keys several times with no sucess, I have confirmed that my app is within my project and I have set all authorizations correctly.
If anyone knows a solutions I would be much aprecciated.
Do you have a more complete code example of what you’re trying to get to work?
Using OAuth2.0 (bearer token) will not work for calling client.get_home_timeline() because this calls GET /2/users/:id/timelines/reverse_chronological | Docs | Twitter Developer Platform which only accepts OAuth1.0a or OAuth2.0 PKCE, not a bearer token which is “App only”.
1 Like
thanks for replying, here it goes:
# OAuth 1.0
import requests # to make requests to the twitter api
import tweepy
client = tweepy.Client(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_toke_secret)
#works
timeline = client.get_home_timeline()
print(timeline)
#does not work
my_id = 944686196331966464
User_tweets = client.get_users_tweets(id='944686196331966464')
print(User_tweets)
(note that in my file I just copy paste all 4 keys and pass them as strings)
This should be
`User_tweets = client.get_users_tweets(id='944686196331966464', user_auth=True)`
Because the default is to use App only Auth, which you have not specified, you are using User Auth when you create the Client with Client(consumer_key=consumer_key, consumer_secret=consumer_secret, access_token=access_token, access_token_secret=access_toke_secret)
1 Like
Thanks a lot, it seems it worked. So just to clarify I just have to set user_auth = True with every request or is there an easier way to it?
Also when using the Auth2.0 I get the 401 error and that method does not resolve the problem
import requests
import tweepy
client = tweepy.Client(bearer_token=bearer_token)
id = ‘1439576232358776833’
timeline = requests.request(method=‘Get’, url=‘https://api.twitter.com/2/users/:id/timelines/reverse_chronological’, params=id)
print(timeline)
It depends on the exact function you’re calling using tweepy - see the docs for the method to check if it needs it or not.
This does not work with Bearer token because the reverse_chronological endpoint ONLY accepts OAuth1.0a or oauth2.0 PKCE, never OAuth2.0 Bearer token.
1 Like