6

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 の位置座標を使用してニューヨーク市からツイートを取得しようとしています。どうすれば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])
4

1 に答える 1

4

4 つの座標が必要です。例:

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

これは、バウンディングボックスを描画できるサイトの最初の Google 検索結果です。ページの左下にある CSV 形式を選択します。

この投稿で述べたように、場所とキーワードの両方でフィルタリングすることはできないことに注意してください。

于 2016-02-08T12:30:32.333 に答える