Skip to content
This repository was archived by the owner on Feb 8, 2024. It is now read-only.
This repository was archived by the owner on Feb 8, 2024. It is now read-only.

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

@slorber

Description

@slorber

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    help wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions