Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/318.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 使用Tweepy从Twitter获取特定位置的推文_Python_Twitter_Geolocation_Tweepy_Tweetstream - Fatal编程技术网

Python 使用Tweepy从Twitter获取特定位置的推文

Python 使用Tweepy从Twitter获取特定位置的推文,python,twitter,geolocation,tweepy,tweetstream,Python,Twitter,Geolocation,Tweepy,Tweetstream,我试图使用Tweepy从特定位置获取推文,但在运行代码时出现此错误 raise TweepError("Wrong number of locations points, " tweepy.error.TweepError: Wrong number of locations points, it has to be a multiple of 4 在我的代码中,我尝试从纽约市获取推文,其中包含纽约的位置坐标。我怎样才能从纽约一个人那里得到推特?我的猜测是使用一系列坐标,比如x,y和y,z。我

我试图使用Tweepy从特定位置获取推文,但在运行代码时出现此错误

raise TweepError("Wrong number of locations points, "
tweepy.error.TweepError: Wrong number of locations points, it has to be a multiple of 4
在我的代码中,我尝试从纽约市获取推文,其中包含纽约的位置坐标。我怎样才能从纽约一个人那里得到推特?我的猜测是使用一系列坐标,比如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])

它需要4个坐标。例如,纽约:

stream.filter(位置=[-74.1687,40.5722,-73.8062,40.9467])

这是谷歌第一个让你画边界框的网站。选择页面左下角的CSV格式

重要的是要注意,如本文所述,您不能同时按位置和关键字进行筛选