I would like to get the tweets that either contain 'love' and/or '#hate' using Python Tweepy. But using my current code as below, it only returns the first term (i.e. 'love'). I have been trying for days to debug and read the Tweepy/Twitter documentation to no avail. Please advice.
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
From looking at the twitter API documentation, the 'or' should be capitalized and should be inside the single quotes:
q = ('love OR #hate')
来源:https://stackoverflow.com/questions/25878188/search-term-intersection-and-union-using-python-tweepy