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

[bug] v1 media upload not working #556

Open
haupt-pascal opened this issue Dec 27, 2024 · 1 comment
Open

[bug] v1 media upload not working #556

haupt-pascal opened this issue Dec 27, 2024 · 1 comment

Comments

@haupt-pascal
Copy link

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)

@francistogram
Copy link

I've been using the v1.uploadMedia for ~2 years and it works fine

Odds are this error is legitimate and you need to figure out what's going on with auth that you're potentially doing incorrectly

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

No branches or pull requests

2 participants