1
編輯:我設法通過使用virtualenv使Twitter工作。不過,我仍然想解決這個問題。Tweepy和Twitter不能一起工作
我成功安裝並使用了Tweepy。然而,當我嘗試只使用Twitter的API,我收到以下錯誤
AttributeError: 'module' object has no attribute 'oauth'
我使用的代碼是從挖掘社交網絡,第2版:
import twitter
def oauth_login():
# XXX: Go to http://twitter.com/apps/new to create an app and get values
# for these credentials that you'll need to provide in place of these
# empty string values that are defined as placeholders.
# See https://dev.twitter.com/docs/auth/oauth for more information
# on Twitter's OAuth implementation.
CONSUMER_KEY = ''
CONSUMER_SECRET = ''
OAUTH_TOKEN = ''
OAUTH_TOKEN_SECRET = ''
auth = twitter.oauth.OAuth(OAUTH_TOKEN, OAUTH_TOKEN_SECRET,
CONSUMER_KEY, CONSUMER_SECRET)
twitter_api = twitter.Twitter(auth=auth)
return twitter_api
,並顯示錯誤下面的調用之後:
我已經安裝的OAuth,我無法弄清楚到底是怎麼回事。我需要安裝Tweepy,因爲我已經編寫了一大段與Tweepy一起工作的代碼,我猜測這個問題是由於安裝了Tweepy而引起的。
編輯:書中的代碼使用https://github.com/sixohsix/twitter
請添加代碼示例,使AttributeError的出現。你如何安裝Tweepy? –
添加了代碼(當然,實際代碼中包含所有的鍵) – Anastasia
您的問題(您需要)安裝了python-twitter和Tweepy,並且只有在安裝時纔會出現錯誤?只是爲了確保我明白你的問題! –