我想使用 Python Tweepy 获取包含“love”和/或“#hate”的推文。但是使用我当前的代码如下,它只返回第一个词(即“爱”)。几天来,我一直在尝试调试和阅读 Tweepy/Twitter 文档,但无济于事。请指教。
import tweepy
import time
ckey = ""
csecret = ""
atoken = ""
asecret = ""
OAUTH_KEYS = {'consumer_key':ckey, 'consumer_secret':csecret,
'access_token_key':atoken, 'access_token_secret':asecret}
auth = tweepy.OAuthHandler(OAUTH_KEYS['consumer_key'], OAUTH_KEYS['consumer_secret'])
api = tweepy.API(auth)
for tweet in tweepy.Cursor(api.search, q=('love' or '#hate'), since='2014-09-15', until='2014-09-16').items(500):
try:
print "Tweet created:", tweet.created_at
print "Tweet:", tweet.text.encode('utf8')
counter += 1
except IOError:
time.sleep(60)
continue