Tweepy + Twitter API v2:我只想为 media_key 提取 tweet.id
Tweepy + Twitter API v2: I want to extract the tweet.id for media_key only
如果我想获取推文 ID 和 media_keys
并且只获取具有 media_keys
的推文 ID 怎么办?
我试图用这个样本来做,但我卡住了:
https://docs.tweepy.org/en/stable/examples.html
client = tweepy.Client(consumer_key=API_KEY, consumer_secret=API_SECRET, access_token=ACCESS_TOKEN, access_token_secret=ACCESS_TOKEN_SECRET, bearer_token=Bearer_token)
counts = 10
search_result = client.get_list_tweets(id='list id', max_results=counts, expansions=["attachments.media_keys"])
tweets = search_result.data
includes = search_result.includes
medias = includes['media']
for tweetid in tweets:
tid = tweetid.id
mediass = {media['media_key']: media for media in medias}
for tweet in tweets:
print(tweet.id, mediass)
您可以检查 Tweet objects 的 attachments
字段以获取附加到推文的媒体的媒体密钥。
如果我想获取推文 ID 和 media_keys
并且只获取具有 media_keys
的推文 ID 怎么办?
我试图用这个样本来做,但我卡住了: https://docs.tweepy.org/en/stable/examples.html
client = tweepy.Client(consumer_key=API_KEY, consumer_secret=API_SECRET, access_token=ACCESS_TOKEN, access_token_secret=ACCESS_TOKEN_SECRET, bearer_token=Bearer_token)
counts = 10
search_result = client.get_list_tweets(id='list id', max_results=counts, expansions=["attachments.media_keys"])
tweets = search_result.data
includes = search_result.includes
medias = includes['media']
for tweetid in tweets:
tid = tweetid.id
mediass = {media['media_key']: media for media in medias}
for tweet in tweets:
print(tweet.id, mediass)
您可以检查 Tweet objects 的 attachments
字段以获取附加到推文的媒体的媒体密钥。