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

Use media_id to upload media #43

Closed
wants to merge 2 commits into from
Closed

Use media_id to upload media #43

wants to merge 2 commits into from

Conversation

GCorbel
Copy link
Contributor

@GCorbel GCorbel commented Mar 24, 2025

X recently changed, so we have to use "media_id" instead of "media_key" in requests to upload media.

It fixes #42

@@ -16,7 +16,7 @@

X::MediaUploader.await_processing(client:, media:)

tweet_body = {text: "Posting media from @gem!", media: {media_ids: [media["media_id_string"]]}}
tweet_body = {text: "Posting media from @gem!", media: {media_ids: [media["id"]]}}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I copy/pasted the example and had :

> media_category = "tweet_video" # other options include: tweet_image, tweet_gif, dm_image, dm_video, dm_gif, subtitles
=> "tweet_video"

> media = X::MediaUploader.chunked_upload(client:, file_path:, media_category:)
=> 
{"id"=>"1904180809726124032",
...

> media
=> 
{"id"=>"1904180809726124032",
 "media_key"=>"7_1904180809726124032",
 "size"=>2107842,
 "expires_after_secs"=>86400,
 "processing_info"=>{"state"=>"pending", "check_after_secs"=>1}}

> X::MediaUploader.await_processing(client:, media:)
=> 
{"expires_after_secs"=>86392,
 "id"=>"1904180809726124032",
 "media_key"=>"7_1904180809726124032",
 "processing_info"=>{"progress_percent"=>100, "state"=>"succeeded"},
 "size"=>2107842,
 "video"=>{"video_type"=>"video/mp4"}}

> tweet_body = {text: "Posting media from @gem!", media: {media_ids: [media["id"]]}}
=> {:text=>"Posting media from @gem!", :media=>{:media_ids=>["1904180809726124032"]}}

> tweet = client.post("tweets", tweet_body.to_json)
=> 
{"data"=>
...

> tweet
=> 
{"data"=>
  {"edit_history_tweet_ids"=>["1904180958837801012"],
   "id"=>"1904180958837801012",
   "text"=>"Posting media from @gem! https://t.co/Sgui6sMm6U"}}

@GCorbel
Copy link
Contributor Author

GCorbel commented Mar 24, 2025

I don't see how the failing mutant test is related to my changes.

@sferik
Copy link
Owner

sferik commented Mar 24, 2025

Hey, I made this change myself right before I saw you submitted this pull request. Sorry about that. Version 0.15.1 has been released with this change.

@sferik sferik closed this Mar 24, 2025
@GCorbel
Copy link
Contributor Author

GCorbel commented Mar 25, 2025

No problem but according to the doc, the parameter has to be media_id even for POST requests. I'm surprised that it still works with media_key but we may have the same issue if X decide to change.

@sferik
Copy link
Owner

sferik commented Mar 25, 2025

@GCorbel Can you re-submit your pull request with all of the conflicts resolved and I'll merge that and release 0.15.2?

@sferik
Copy link
Owner

sferik commented Mar 27, 2025

@GCorbel Never mind. I was able to pull in all the changes from your branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

X::BadRequest when using await_processing
2 participants