问题
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