Unauthorized when POST to Tweets endpoint
See original GitHub issuehttps://twittercommunity.com/t/post-request-returning-error-401-unauthorized/162950/4
following the example in the README, let response = await client.get('tweets', { ids: id }) works as expected, but let response = await client.post('tweets', { text: message }) fails with { code: 401, details: 'Unauthorized' }. nodejs 17.2.0, windows.
It’s expected that POST should authenticate using the same method and send a tweet successfully.
Full code example:
const Twitter = require("twitter-v2")
const client = new Twitter({
consumer_key: process.env.TWITTER_CONSUMER_KEY,
consumer_secret: process.env.TWITTER_CONSUMER_SECRET,
access_token_key: process.env.TWITTER_ACCESS_TOKEN_KEY,
access_token_secret: process.env.TWITTER_ACCESS_TOKEN_SECRET
});
async function sendTweet(message) {
try {
const response = await client.post('tweets', { text: message })
console.log(response)
} catch (err) {
console.error(err)
}
}
async function getTweet(id) {
try {
const response = await client.get('tweets', { ids: id })
console.log(response)
} catch (err) {
console.error(err)
}
}
sendTweet('test tweet!')
getTweet('1228393702244134912')
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:8
Top Results From Across the Web
POST request returning ERROR 401 "Unauthorized"
There was a problem authenticating your request. This could be due to missing or incorrect authentication credentials. This may also be returned ...
Read more >Twitter API returned a 401 (Unauthorized), An error ...
After running it I receive the following error: python tweet.py previous_cursor previous_cursor_str next_cursor ids next_cursor_str Twitter API ...
Read more >Twitter API Response Codes & Error Support
Corresponds with HTTP 403. Thrown when a Tweet cannot be posted due to the user having no allowance remaining to post. Despite the...
Read more >Error 401, "unauthorized" while trying to connect to Twitter's ...
You have the right idea in terms of getting started. A 401 error usually mean there was a problem authenticating your request. From...
Read more >Not able to hit Twitter API through POSTMAN - Microsoft Q&A
Error: When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I changed to twitter-api-v2 and that works perfectly
I found it. I was confusing about the user flow authentication. But how i will using my own account its not necessary!
Thanks for the response men!