-
Notifications
You must be signed in to change notification settings - Fork 215
Open
Description
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:
- Set up a Twitter Developer App with "Read and Write" permissions.
- Generate API Key, API Secret, Access Token, and Access Token Secret from the developer portal for the app and user.
- 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();
- 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.

Metadata
Metadata
Assignees
Labels
No labels