Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter API returned a 401 (Unauthorized), An error occurred processing your request

Here's my code for getting the followers and updating a status:

from twython import Twython,TwythonError
APP_KEY='mykey'
APP_SECRET='mysecret'
OAUTH_TOKEN='mytoken'
OAUTH_TOKEN_SECRET='mytokensecret'
twitter = Twython(APP_KEY, APP_SECRET, OAUTH_TOKEN, OAUTH_TOKEN_SECRET)
followers = twitter.get_followers_ids(screen_name = "darcythegreat")

for follower_id in followers:
    print follower_id

try:
    twitter.update_status(status='My first status using Twython')
except TwythonError as e:
    print e

And here's the LINK to my Twitter.

After running it I receive the following error:

python tweet.py 
previous_cursor
previous_cursor_str
next_cursor
ids
next_cursor_str
Twitter API returned a 401 (Unauthorized), An error occurred processing your request.

Can you please let me know which steps I am missing?

like image 257
Mona Jalal Avatar asked May 25 '26 15:05

Mona Jalal


1 Answers

There are several reasons why a 401 can occur, some that aren't related to the code you've written. A common reason is a difference in clock times between your and Twitter's server. Here's a link to the Twitter OAuth FAQ: https://developer.twitter.com/en/docs/authentication/faq

like image 174
Joe Mayo Avatar answered May 27 '26 04:05

Joe Mayo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!