Post tweet with tweepy
16,625
Solution 1
In the application's settings, set your Application Type to "Read and Write". Then renegotiate your access token.
Solution 2
the code works for me with only
api.update_status (**status** = 'Updating using OAuth authentication via Tweepy!')
Author by
Riccardo Gai
Updated on July 18, 2022Comments
-
Riccardo Gai almost 2 years
I'm trying to post a tweet with the tweepy library. I use this code:
import tweepy CONSUMER_KEY ="XXXX" CONSUMER_SECRET = "XXXX" ACCESS_KEY = "XXXX" ACCESS_SECRET = "XXXX" auth = tweepy.OAuthHandler(CONSUMER_KEY, CONSUMER_SECRET) auth.set_access_token(ACCESS_KEY, ACCESS_SECRET) api = tweepy.API(auth) api.update_status('Updating using OAuth authentication via Tweepy!')
But when I run the application, I receive this error:
raise TweepError(error_msg, resp) TweepError: Read-only application cannot POST.
How can I fix this?
-
TedCap over 9 yearsWhat do you mean by renegotiate your access token? Do you need a new access token if the app was read only when you got the original token?
-
Shon over 9 yearsI just figured out this part myself. After changing the application type, you must select Regenerate My Access Token and Token Secret for the account linked with your app. And, as @TedCap said, you will be issued new tokens reflecting the change in permissions for the associated account.
-
Adam Christianson almost 9 yearsActually this IS answer, just to a slightly different issue and it helped me, so I want to comment on this. I was getting a status response of '400' back from Twitter when I was using the Tweepy call:
api.update_status('Updating using OAuth authentication via Tweepy!')
but I was able to fix the issue by changing the method parameters to:api.update_status(status = 'Updating using OAuth authentication via Tweepy!')
The Tweepy docs seem to be unclear about this nuance.