I am using Twitter API by the package Twitter for Node.js.
Right now I succeed reading tweets using stream, but I failed to write tweets. I got 401 error which means Unauthorized according to Twitter Developer Documentation.
The code is here:
const Twitter = require('twitter');
const twitterClient = new Twitter({
consumer_key: TwitterConsumerKey,
consumer_secret: TwitterConsumerSecret,
access_token_key: TwitterAccessTokenKey,
access_token_secret: TwitterAccessTokenSecret
});
twitterClient.post('statuses/update', { status: 'Hello World!' }, (err, tweet, res) => {
if (err) throw err;
console.log(tweet);
console.log(res);
});
I did give write access. What could be other reasons causing this? Thanks
I made it work. Before I changed my access from "read" to "read, write, and direct messages". And I did regenerate my "consumer key and secret", also "access token and token secret" several times.
It should work, but it wasn't.
At last I totally delete the app on Twitter and recreated it, then it works!
Hope this can help people who met this weird issue.