Return Unique Tweet id with Tweepy Json

天大地大妈咪最大 提交于 2019-12-08 06:45:27

问题


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"]

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


回答1:


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.

Second, use the tweet id that is already set by twitter. You can obtain it from all_data["id"].

i.e: 'id': 640415654723786993,

Not to be confused with all_data["user"]["id"]



来源:https://stackoverflow.com/questions/32724453/return-unique-tweet-id-with-tweepy-json

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!