使用 Tweepy Json 返回唯一的推文 ID [英] Return Unique Tweet id with Tweepy Json
问题描述
希望返回并创建我自己或为每个解析的推文捕获一个唯一的 tweet_id...
Looking to either return and create myself or capture a unique tweet_id for each tweet that is parsed...
class listener(StreamListener):
def on_data(self, data):
all_date = json.load(data)
tweet = all_data["text"]
username = all_data["user"]["screen_name"]
在这里我想创建一个名为 tweet_id 的变量并从 all_data 中的相应值返回它,或者创建我自己的 id 系统
here I'd like to create a variable called tweet_id and return that from a corresponding value within all_data and or create my own id system
推荐答案
首先,我认为您的意思可能是 json.loads()
注意 s.json.load() 用于读取文件,而不是接受 str
其中 data
的类型.
First of all I think you may have meant json.loads()
notice the s. json.load() is use to read a file, not accept str
which the type of data
.
其次,使用twitter已经设置的tweet id.您可以从 all_data["id"]
获取它.
Second, use the tweet id that is already set by twitter. You can obtain it from all_data["id"]
.
即:'id':640415654723786993,
不要与all_data["user"]["id"]
这篇关于使用 Tweepy Json 返回唯一的推文 ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!