I am trying to create a very simple bot using twitter-api-v2, NodeJS and Twitter's free tier for developers. I have tried following a tutorial by Dom the dev but I keep running into the same bug, no matter what I try.
The error message
You currently have access to a subset of Twitter API v2 endpoints and limited v1.1 endpoints (e.g. media post, oauth) only. If you need access to this endpoint, you may need a different access level. You can learn more here: https://developer.twitter.com/en/portal/product
What I have tried so far
- Making sure my settings are correct on https://developer.twitter.com using two different accounts, including one that should be working because it has worked in the past (more precisely in October) It was used by somebody else than myself.
- Making sure my code doesn't contain any typo.
- Searching on the Web. Incidentally, the issue I'm talking about seems common, but the solution is not so clear.
My project has three files
twitterClient.js
const { TwitterApi } = require("twitter-api-v2");
const client = new TwitterApi({
appKey: "",
appSecret: "",
accessToken: "",
accessSecret: ""
});
const rwClient = client.readWrite;
module.exports = rwClient;
index.js
const rwClient = require("./twitterClient.js");
const tweet = async () => {
try {
await rwClient.v1.tweet("Good morning!");
} catch (e) {
console.error(e);
}
}
tweet();
package.json
"dependencies": {
"twitter-api-v2": "^1.15.2"
}
Here is the answer to my own question:
This line:
Has to be changed for this:
And voilà!