tweepy icon indicating copy to clipboard operation
tweepy copied to clipboard

No media when retreiving a list of tweets

Open phisanti opened this issue 3 years ago • 5 comments

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?

phisanti avatar Jul 31 '22 20:07 phisanti

https://docs.tweepy.org/en/stable/client.html#tweepy.Client.get_list_tweets get_list_tweets has not parameter with name media_fields

ghost avatar Aug 03 '22 20:08 ghost

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?

phisanti avatar Aug 06 '22 11:08 phisanti

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

ghost avatar Aug 07 '22 15:08 ghost

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?

image

phisanti avatar Aug 07 '22 15:08 phisanti

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.

calvinh99 avatar Aug 10 '22 18:08 calvinh99

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.

phisanti avatar Aug 11 '22 11:08 phisanti

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.

R2SH2 avatar Aug 17 '22 16:08 R2SH2

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.fields argument 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.fields in 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 avatar Aug 19 '22 15:08 Harmon758

@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!

chrisgoddard avatar Aug 19 '22 16:08 chrisgoddard

I'll have a v4.10.1 bugfix release out soon.

Harmon758 avatar Aug 20 '22 14:08 Harmon758

v4.10.1 has been released with this fix now.

Harmon758 avatar Aug 23 '22 02:08 Harmon758