Using Twython to Access the Twitter API


Hey together

I am currently doing my first steps towards using the Twitter API, I am using Anacoda and Twython. However, I am always getting the following error message:

"twython.exceptions.TwythonAuthError: Twitter API returned a 401 (Unauthorized), Invalid or expired token.t

This is the code I am using:

from twython import Twython, TwythonError

# Requires Authentication as of Twitter API v1.1
twitter = Twython('XYZ', 'XYZ', 'XYZ', 'XYZ')
    search_results ='WebsDotCom', count=50)
except TwythonError as e:
    print e

for tweet in search_results['statuses']:
    print 'Tweet from @%s Date: %s' % (tweet['user']['screen_nam\
    print tweet['text'].encode('utf-8'), '\n'from twython import Twython, TwythonError

Does anybody whats wrong with the code? Of course, I am not using thr XYZ as the authentification tokens.


I’d make sure my PC / server clock is in sync (it affects OAuth signatures) and my tokens are definitely exactly as they are in the apps page on

closed #3

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.