I am working on twitter API and getting error: TwitterError: [{u'message': u'Invalid or expired token.', u'code': 89}]

196 Views Asked by At

code:

import twitter

consumer_key = 'xyz'
consumer_secret = 'xyz'
access_token  = 'xyz-xyz'
access_token_secret = 'xyz'

my_api = twitter.Api(consumer_key='consumer_key',
                  consumer_secret='consumer_secret',
                  access_token_key='access_token',
                  access_token_secret='access_token_secret')

users = my_api.GetFriends()
print([u.name for u in users])

when I run my python script I am getting below error, I have verified the access token key and it as per the details I generated over twitter app.

error:

C:\Python\twitter_api>python twit_it_up.py
Traceback (most recent call last):
File "twit_it_up.py", line 13, in <module>
users = my_api.GetFriends()
File "C:\Python27\lib\site-packages\twitter\api.py", line 2776, in 
GetFriends
include_user_entities)
File "C:\Python27\lib\site-packages\twitter\api.py", line 2671, in 
_GetFriendsFollowers
include_user_entities)
File "C:\Python27\lib\site-packages\twitter\api.py", line 2499, in 
_GetFriendsFollowersPaged
data = self._ParseAndCheckTwitter(resp.content.decode('utf-8'))

File "C:\Python27\lib\site-packages\twitter\api.py", line 4908, in 
_ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "C:\Python27\lib\site-packages\twitter\api.py", line 4928, in 
_CheckForTwitterError
raise TwitterError(data['errors'])
twitter.error.TwitterError: [{u'message': u'Invalid or expired token.', 
u'code': 89}]
0

There are 0 best solutions below