question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to use chucked media upload / mediaUploadAppend: "Could not authenticate you"

See original GitHub issue

Describe the bug

The chunked media upload is required to upload videos, but it seems impossible to use currently due to an auth failure.

Unable to authenticate on the 2nd / APPEND endpoint of the chunked media upload.

  const mediaUploadInitResult = await twitterClient.media.mediaUploadInit({
    command: "INIT",
    media_type: "video/mp4",
    media_category: "tweet_video",
    total_bytes: 56789710,
  });
  console.log("mediaUploadInitResult", mediaUploadInitResult);

  const binary = fs.readFileSync(filePath);

  const base64 = fs.readFileSync(filePath, { encoding: "base64" });

  const mediaUploadAppend = await twitterClient.media.mediaUploadAppend({
    command: "APPEND",
    media_id: mediaUploadInitResult.media_id_string,
    media_data: base64,
    // media: binary,
    segment_index: 0,
  });
  console.log("mediaUploadAppend", mediaUploadAppend);

I tried both with binary or base64 and it does not change anything. Note non-chunked image upload works fine for me.

mediaUploadInitResult {
  media_id: 1374383257052012500,
  media_id_string: '1374383257052012546',
  expires_after_secs: 86399,
  media_key: '7_1374383257052012546'
}
Error
{
  statusCode: 401,
  data: '{"errors":[{"code":32,"message":"Could not authenticate you."}]}'
}
error Command failed.

The first INIT call works, but the 2nd APPEND call fails.

It looks like a problem related to how the OAuth signature is handled for multipart uploads, according to this blog post: https://retifrav.github.io/blog/2019/08/22/twitter-chunked-upload-video/

This page also mentions:

image

I believe there may be something wrong that prevents chunked upload in the transport layer here: https://github.com/FeedHive/twitter-api-client/blob/master/src/base/Transport.ts

There are not many examples on the internet using NodeJS and the official doc is using twurl unfortunately. This could be helpful: https://medium.com/ameykpatil/how-to-publish-an-external-video-to-twitter-node-js-version-89c03b5ff4fe

Would be happy to help solve this

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:11

github_iconTop GitHub Comments

3reactions
TotomiEciocommented, Aug 17, 2021

Hi! I’m still having the same issues with the APPEND request. Have you made any progress?

1reaction
SimonHoibergcommented, Mar 24, 2021

Thanks a lot, we’ll take a look 😊

Read more comments on GitHub >

github_iconTop Results From Across the Web

FINALIZE step in media chunk upload giving 400 error ...
I am trying to upload image or video using chunk uploading steps step 1 and 2 ... use chucked media upload / mediaUploadAppend:...
Read more >
Twitter API POST media/upload (chunked) error "Not found"
I believe your problem might be here: ... The NOT_FOUND exception in your APPEND calls means the Media ID you provided can't be...
Read more >
Chunked media upload | Docs | Twitter Developer Platform
For video or chunked uploads, you must: Initialize the upload using the INIT command; Upload each chunk of bytes using the APPEND command;...
Read more >
Chunked upload to Twitter with C# / .NET Core
The result video file is accepted by Twitter with no problems. Upload process. Here're some official guidelines. Eventually you will come to ...
Read more >
How to Fix the WordPress HTTP Error (Uploading Image to ...
WordPress should automatically append a number on the end if you try to upload a duplicate file name, but in case that doesn't...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found