3

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?

Mona Jalal
  • 34,860
  • 64
  • 239
  • 408

3 Answers3

2

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

Joe Mayo
  • 7,501
  • 7
  • 41
  • 60
  • 2
    This was indeed the case for me. my pc was set 1 hour in the future without me noticing and kept getting 401; solved by resetting the correct time. – tonnoz Mar 13 '19 at 07:55
1

This StackOverflow answer worked for me. I had to change the permissions on my account. Also, the code given here is much simpler:

Community
  • 1
  • 1
Basil
  • 403
  • 5
  • 14
  • I have the same exact problem: a 401 error when calling for get_followers_ids, but the linked answer seems to not work for me. I understand this is an old answer but still, any suggestion? – GRquanti Sep 24 '18 at 03:18
1

Just Regenerating API,API-SECRET,ACCESS, ACCESS-TOKEN...Worked for me

Atif Shaik
  • 11
  • 2