tweepy
tweepy copied to clipboard
No media when retreiving a list of tweets
I am trying to get a tweets from a list with its media but apparently, the media_field is not present and gives the error:
x = client.get_list_tweets(4343, expansions=["attachments.media_keys", "author_id"],
tweet_fields = ['created_at', 'text', 'id', 'attachments', 'author_id', 'entities'],
media_fields=['preview_image_url', 'url'])
and here is the error
The query parameter [media_fields] is not one of [id,max_results,pagination_token,expansions,tweet.fields,media.fields,poll.fields,place.fields,user.fields]
Any help?
https://docs.tweepy.org/en/stable/client.html#tweepy.Client.get_list_tweets get_list_tweets has not parameter with name media_fields
That is interesting because the error message indicates that there is a media.field. Moreover, twitter API (https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets) indicates that the media.fields argument is available. Did I understand that wrong or is a matter to implement the feature in the python version?
try
x = client.get_list_tweets(4343, expansions=["attachments.media_keys", "author_id"],
tweet_fields = ['created_at', 'text', 'id', 'attachments', 'author_id', 'entities']
)
and watch if print(x.media) exist. If a media.field exist then x.media exist and look his value
This is what I see. I see attributes x.includes, which contains the media keys but no media attribute. Is it at least possible retrieve the media URL using the media.keys?

If you look at the twitter api v2 documentation, the media url is retrieved by including expansions=attachments.media_keys&media.fields in the http request.
I have just tried @calvinh99 suggestion with no success again:
tweepy.errors.BadRequest: 400 Bad Request
The `expansions` query parameter value [attachments.media_keys&media.fields] is not one of [author_id,referenced_tweets.id,referenced_tweets.id.author_id,entities.mentions.username,attachments.poll_ids,attachments.
media_keys,in_reply_to_user_id,geo.place_id]
I guess a possible workaround is to get the id of the tweet and, from there, get each tweet with the media URL. Unless you think it is possible to retrieve the media using the media keys.
im having this same problem too i cant find any info on it, im trying to get image url using client.get_users_tweets() but i cant seem to get preview_image_url.
Thanks for the bug report. This should be fixed now.
This was due to the Twitter API documentation for the endpoint this method uses not listing media.fields, place.fields, or poll.fields as parameters, which got translated into Tweepy not supporting them as parameters.
Moreover, twitter API (https://developer.twitter.com/en/docs/twitter-api/lists/list-tweets/api-reference/get-lists-id-tweets) indicates that the
media.fieldsargument is available.
@phisanti I don't see that on that page, and place.fields and poll.fields are actually missing as well.
@spirale21 Client.get_list_tweets returns a Response object, which doesn't have a media attribute.
If you look at the twitter api v2 documentation, the media url is retrieved by including
expansions=attachments.media_keys&media.fieldsin the http request.
@calvinh99 @phisanti Yes, the request URL ends up with media.fields as a URL parameter key, but it requires a value as well and you need to pass the parameter individually through Tweepy, not as part of a different parameter.
@R2sh2 That's not related to this issue.
Client.get_users_tweets supports media.fields.
Feel free to start a new discussion if you need help with using the parameter, but you'll need to provide more information, like your code and expected and actual behavior.
@Harmon758 how soon do you think you could create a new release for this? I can pull the dev version locally for the fix but I'd prefer not to have to push that to my production environment if possible
Thanks!
I'll have a v4.10.1 bugfix release out soon.
v4.10.1 has been released with this fix now.