Skip to content

[bug] v1 media upload not working #556

Open
@haupt-pascal

Description

@haupt-pascal

Twitter API v2 Media Upload Authentication Issue

Description

When trying to upload media using v1 API with OAuth 1.0a app credentials while posting with OAuth 2.0 user token, getting 401 authentication errors.

Environment

  • node-twitter-api-v2: latest
  • Node.js: 18.x
  • TypeScript: 5.x

Code

const v1Client = new TwitterApi({
    appKey: process.env.TWITTER_API_KEY,
    appSecret: process.env.TWITTER_API_SECRET,
    accessToken: process.env.TWITTER_ACCESS_TOKEN,
    accessSecret: process.env.TWITTER_ACCESS_SECRET,
});

const v2Client = new TwitterApi(connection.access_token); // OAuth 2.0 user token

try {
    const mediaId = await v1Client.v1.uploadMedia(imageBuffer, {
        mimeType: "image/jpeg",
        additionalOwners: [connection.member_id],
    });

    return await v2Client.v2.tweet({
        text: content,
        media: { media_ids: [mediaId] }
    });
} catch (error) {
    console.error("Error:", error);
}

Error:

Twitter media upload error: {
ERROR Twitter media upload error: { errors: [ { message: 'Could not authenticate you', code: 32 } ] }
ERROR Twitter API error: Media upload failed: Request failed with code 401 - Could not authenticate you (Twitter code 32)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions