Obtendo o Tweepy para rodar [fechado]

1

Não consigo fazer com que tweepy funcione. O que estou fazendo errado?:

nuc@nuc:~$ python
Python 2.7.8 |Anaconda 2.1.0 (64-bit)| (default, Aug 21 2014, 18:22:21) 
[GCC 4.4.7 20120313 (Red Hat 4.4.7-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
Anaconda is brought to you by Continuum Analytics.
Please check out: http://continuum.io/thanks and https://binstar.org
>>> import tweepy
>>> user = tweepy.api.get_user('twitter')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/nuc/anaconda/lib/python2.7/site-packages/tweepy/binder.py", line 239, in _call
    return method.execute()
  File "/home/nuc/anaconda/lib/python2.7/site-packages/tweepy/binder.py", line 189, in execute
    raise TweepError('Failed to send request: %s' % e)
tweepy.error.TweepError: Failed to send request: local variable 'auth' referenced before assignment
>>> 
    
por empedokles 19.03.2015 / 15:14

1 resposta

2

Você não pode usar a API do tweepy sem registrar suas credenciais.

Tweepy tries to make OAuth as painless as possible for you. To begin the process we need to register our client application with Twitter. Create a new application and once you are done you should have your consumer token and secret. Keep these two handy, you’ll need them.

Veja este exemplo código:

from __future__ import absolute_import, print_function

import tweepy

# == OAuth Authentication ==
#
# This mode of authentication is the new preferred way
# of authenticating with Twitter.

# The consumer keys can be found on your application's Details
# page located at https://dev.twitter.com/apps (under "OAuth settings")
consumer_key=""
consumer_secret=""

# The access tokens can be found on your applications's Details
# page located at https://dev.twitter.com/apps (located
# under "Your access token")
access_token=""
access_token_secret=""

auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.secure = True
auth.set_access_token(access_token, access_token_secret)

api = tweepy.API(auth)

# If the authentication was successful, you should
# see the name of the account print out
print(api.me().name)

Fonte: link

    
por Sylvain Pineau 19.03.2015 / 15:34