0

Under python2.7 and already installed the requirements.txt from the twitter-python Building section

It's the first time I'm jumping in, and following the basics steps to ensure is everything okay as described here in this link twitter-python Documentation section, I'm getting an error.

Here the typen at command line Python shell:

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

The error:

>>> print api.VerifyCredentials()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-  packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5209, in VerifyCredentials
data = self._ParseAndCheckTwitter(json.content)
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5462, in _ParseAndCheckTwitter
self._CheckForTwitterError(data)
File "/home/ubuntu/.virtualenvs/twitter/local/lib/python2.7/site-packages/python_twitter-1.2-py2.7.egg/twitter.py", line 5487, in _CheckForTwitterError
raise TwitterError(data['errors'])
twitter.TwitterError: [{u'message': u'Invalid or expired token', u'code': 89}]

What could I be missing here?

2 Answers 2

3

You need to replace 'consumer_key', 'consumer_secret', 'access_token', and 'access_token_secret' with their actual values. You can either put those values directly in the twitter.Api() call, or assign their values to variables:

>>> # all these values are just random, you'll need to use your own values
>>> c_key = '123456'
>>> c_secret = 'a88d098cd76'
>>> token = '98765'
>>> token_secret = 'ad98c63e87f00'
>>> api = twitter.Api(consumer_key=c_key,
                      consumer_secret=c_secret,
                      access_token_key=token,
                      access_token_secret=token_secret)
Sign up to request clarification or add additional context in comments.

1 Comment

oh I see! How blind I was!? I thought that would work magically like things usually do in programming terms. Thanks Matt!
1

I'm not sure but it looks like you need a valid consumer_key, consumer_secret, access_token_key and access_token_secret. This will involve you setting up your own app on twitter.com and using the consumer keys/secrets and test access_token keys/secrets to get started.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.