[英]I want to store the IDs of some tweets using tweepy
This code prints the IDs but also raises a TypeError此代码打印 ID,但也会引发 TypeError
for tweet in client.search_recent_tweets(search_string):
for tweet_id in tweet:
print(tweet_id['id'])
Simply printing Tweet gives the following data只需打印 Tweet 即可提供以下数据
Response(data=[<Tweet id=#ID text='#text'>], includes={}, errors=[], meta={'newest_id': '#ID of first tweet', 'oldest_id': '#ID of last tweet', 'result_count': 10, 'next_token': '#Token no.'})
I basically want to extract the Tweet IDs我基本上想提取推文 ID
I don't understand how your double loop is supposed to work.我不明白你的双循环应该如何工作。
Anyway, you can see that the tweets are in the response.data
, so simply iterate through it:无论如何,您可以看到推文位于
response.data
中,因此只需遍历它:
response = client.search_recent_tweets(search_string) # Get the API response
tweets = response.data # Tweets are the data
for tweet in tweets: # Iterate through the tweets
print(tweet.id) # You can now access their id
Here is documentation on how to get tweet fields.这是有关如何获取推文字段的文档。 - https://docs.tweepy.org/en/stable/examples.html
- https://docs.tweepy.org/en/stable/examples.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.