Skip to content

Unable to tweet using api #594

@lazydevpro

Description

@lazydevpro

Describe the bug
Unable to tweet using OAuth 1.0a User Context credentials, even after setting app permissions to "Read and Write" and regenerating all tokens. Always receive a 401 Unauthorized error.

To Reproduce
Steps to reproduce the behavior:

  1. Set up a Twitter Developer App with "Read and Write" permissions.
  2. Generate API Key, API Secret, Access Token, and Access Token Secret from the developer portal for the app and user.
  3. Use the following code to attempt to send a tweet:
const { TwitterApi } = require('twitter-api-v2');

const client = new TwitterApi({
  appKey: 'MY_API_KEY',
  appSecret: 'MY_API_SECRET',
  accessToken: 'MY_ACCESS_TOKEN',
  accessSecret: 'MY_ACCESS_SECRET',
});

async function main() {
  try {
    const response = await client.v2.tweet('Test tweet from API');
    console.log('Tweet sent! Response:', response);
  } catch (err) {
    console.error('Failed to send tweet:', err);
    if (err.toJSON) {
      console.error('Error details:', err.toJSON());
    }
  }
}

main();
  1. Error stack trace:
ApiResponseError: Request failed with code 401
    at RequestHandlerHelper.createResponseError ...
  data: {
    title: 'Unauthorized',
    type: 'about:blank',
    status: 401,
    detail: 'Unauthorized'
  }

Expected behavior
The tweet should be posted to the authenticated user's timeline.

Version
-Node.js version: (e.g., v18.16.0)
-Lib version: (e.g., [email protected])
-OS: macOS Sonoma 14.5

Additional context
Have permissions correctly set up. I have also tried the same thing with a different account, and still encountered the same issues. Also, I am on the free tier as of now.

Image

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