0

I want to show image url of tweet. I get tweet data by using get_tweet like this code.

tweet_ids = [166xxxxxxxxx]

tweets = client.get_tweets(tweet_ids, tweet_fields=['author_id'],media_fields=['preview_image_url'])

Then I try to get list of media from the includes object

media = {m["media_key"]: m for m in tweets.includes['media']}

It show error like this.

---> 13 media = {m["media_key"]: m for m in tweets.includes['media']}
     14 for media in tweets.media:
     15   attachments = tweet.attachments

KeyError: 'media'

If I use for loop to get url like this.

for media in tweets.media:
  attachments = tweet.attachments

  if(attachments['media_keys'] != None):

   media_keys = attachments['media_keys']
   print(media[media_keys[0]].preview_image_url)

It show error.

AttributeError: 'Response' object has no attribute 'media'

How to fix it?

user572575
  • 1,009
  • 3
  • 25
  • 45

0 Answers0