【问题标题】:Get location specific tweets from Twitter using Tweepy使用 Tweepy 从 Twitter 获取特定位置的推文
【发布时间】:2016-05-18 00:39:53
【问题描述】:

我正在尝试使用 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])

【问题讨论】:

    标签: python twitter geolocation tweepy tweetstream


    【解决方案1】:

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

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

    Here 是第一个让您绘制边界框的网站的谷歌搜索结果。选择页面左下角的 CSV 格式。

    请务必注意,正如post 中所述,您不能同时按位置和关键字进行过滤。

    【讨论】:

      猜你喜欢
      • 2021-02-25
      • 2011-12-27
      • 2015-10-08
      • 2017-02-11
      • 2016-10-20
      • 2016-07-29
      • 1970-01-01
      • 1970-01-01
      • 2017-09-16
      相关资源
      最近更新 更多