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
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:
await rwClient.v1.tweet("Good morning!");
Has to be changed for this:
await rwClient.v2.tweet("Good morning!");
And voilĂ !