我正在尝试使用Tweepy从特定位置获取推文,但运行代码时出现以下错误。
raise TweepError("Wrong number of locations points, "
tweepy.error.TweepError: Wrong number of locations points, it has to be a multiple of 4
我的代码中,我试图获取纽约市的推文,并带有NY的位置坐标。如何仅获取来自纽约的推文?我猜想可以使用一系列坐标,例如在x,y和y,z之间。我该怎么做呢?
以下是我的代码:
class StdOutListener(StreamListener):
""" A listener handles tweets are the received from the stream.
This is a basic listener that just prints received tweets to stdout.
"""
def on_data(self, data):
try:
print(data)
saveFile = open('newtweets.csv', 'a')
saveFile.write(data)
saveFile.write('/n').encode("utf-8")
saveFile.close()
return True
except BaseException:
print ('failed ondata')
time.sleep(5)
def on_error(self, status):
print(status.encode("utf-8"))
if __name__ == '__main__':
l = StdOutListener()
auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_token_secret)
#ASK FOR KEYWORD TO COLLECT DATA
user_keyword=input("What keyword do you want to mine?")
stream = Stream(auth, l)
stream.filter(locations=[40.7127,74.0059], track=[user_keyword])