我如何在Tweepy Python中接收整个Tweet?

2023-12-09 17:38:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我用Python创建了一个流程序来接收tweet,但是我注意到它只返回tweet的部分文本。我研究过类似的问题,知道我必须在某个地方插入'tweet\u mode=“extended”',并将其插入到流中,但似乎不起作用。你知道吗

auth = OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_token, access_secret)

class MyListener(StreamListener):
    def on_data(self, data):
        with open(file_name, "a") as file:
            tweetDict = {"text": "", "coordinates": ""}
            tweet = json.loads(data)
            json.dump(tweet, file, indent=4)
            file.write("\n")
            return True

twitter_stream = Stream(auth, MyListener(), tweet_mode="extended")
twitter_stream.filter(track=[target])

Tags: 程序tokenauthjsonextendeddatastreamsecret