2013-07-08 90 views
0

我对Twitter API相当陌生。我更新了Tweepy。我不知道什么是错用此代码,如何解决它,使之成为Twitter的API的新版本的工作:迁移到Twitter API版本1.1(?)[重复]

import oauth, tweepy 
from time import sleep 

#stars is confident information 
username = "*******" 
password = "***********" 
auth = tweepy.BasicAuthHandler(username, password) 
api = tweepy.API(auth) 

api.update_status('hello from tweepy!') 

终端显示我:

$ python py/twi.py 
Traceback (most recent call last): 
    File "py/twi.py", line 11, in <module> 
    api.update_status('hello from tweepy!') 
    File "/usr/lib/python2.7/dist-packages/tweepy/binder.py", line 179, in _call 
    return method.execute() 
    File "/usr/lib/python2.7/dist-packages/tweepy/binder.py", line 162, in execute 
    raise TweepError(error_msg, resp) 
tweepy.error.TweepError: [{'message': 'The Twitter REST API v1 is no longer active. Please migrate to  API v1.1. https://dev.twitter.com/docs/api/1.1/overview.', 'code': 68}] 

请帮助。

回答

0

根据this google groups post,tweepy应该支持1.1 API。您的错误消息报告说,tweepy正在尝试使用1.0 API。我怀疑你的更新失败了。尝试卸载并重新安装tweepy。你使用的是什么版本的tweepy? tweepy.__version__应该是2.0

0

您正在使用带有用户名和密码的基本身份验证。但是,Twitter API 1.1仅支持OAuth。这里是你如何通过OAuth和Tweepy验证:

auth = tweepy.OAuthHandler(consumer_key, consumer_secret) 
auth.set_access_token(key, secret) 

根据this page