Using Twython to Access the Twitter API


#1

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')
try:
    search_results = twitter.search(q='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\
                                       e'].encode('utf-8'),
                                       tweet['created_at'])
    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.


#2

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 https://developer.twitter.com/en/apps


closed #3

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