Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No media when retreiving a list of tweets #1931

Closed
phisanti opened this issue Jul 31, 2022 · 11 comments
Closed

No media when retreiving a list of tweets #1931

phisanti opened this issue Jul 31, 2022 · 11 comments
Labels
API This is regarding Twitter's API Bug This is regarding a bug with the library Documentation This is regarding the library's documentation

Comments

@phisanti
Copy link

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?

@ghost
Copy link

ghost commented Aug 3, 2022

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

@phisanti
Copy link
Author

phisanti commented Aug 6, 2022

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?

@ghost

This comment was marked as resolved.

@phisanti
Copy link
Author

phisanti commented Aug 7, 2022

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

@calvinh99

This comment was marked as resolved.

@phisanti
Copy link
Author

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.

@R2SH2

This comment was marked as off-topic.

@Harmon758 Harmon758 added Bug This is regarding a bug with the library API This is regarding Twitter's API Documentation This is regarding the library's documentation labels Aug 19, 2022
@Harmon758
Copy link
Member

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.

@chrisgoddard
Copy link

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

@Harmon758
Copy link
Member

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

@Harmon758
Copy link
Member

v4.10.1 has been released with this fix now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API This is regarding Twitter's API Bug This is regarding a bug with the library Documentation This is regarding the library's documentation
Projects
None yet
Development

No branches or pull requests

5 participants