Запуск Tweepy [закрыто]

Я не могу заставить работать tweepy . Что я делаю не так?:

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
>>> 
1
задан 19 March 2015 в 19:37

1 ответ

Вы не можете использовать tweepy API, не регистрируя Ваши учетные данные.

Tweepy пытается сделать OAuth максимально безболезненным для Вас. Для начала процесса, мы должны зарегистрировать наше клиентское приложение в Twitter. Создайте новое приложение и как только Вы сделаны, у Вас должны быть свой потребительский маркер и секрет. Сохраните эти два удобными, you’ll нужны они.

Взгляд на этот пример код:

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)

Источник: http://docs.tweepy.org/en/v3.2.0/auth_tutorial.html

2
ответ дан 19 March 2015 в 19:37

Другие вопросы по тегам:

Похожие вопросы: