'Twitter API v2 Error "You currently have Essential access.."

I'm trying to create a tweet with twitter API v2 (npm/twitter-api-v2). But im getting this Error given below:


ApiResponseError: Request failed with code 403 - You currently have Essential access which includes access to Twitter API v2 endpoints only. If you need access to this endpoint, you’ll need to apply for Elevated access via the Developer Portal. You can learn more here: https://developer.twitter.com/en/docs/twitter-api/getting-started/about-twitter-api#v2-access-leve (Twitter code 453)

My code

import { TwitterApi } from "twitter-api-v2";
import "dotenv/config";

var client = new TwitterApi({
   appKey: process.env.APP_KEY,
   appSecret: process.env.APP_SECRET,
   accessToken: process.env.ACCESS_TOKEN,
   accessSecret: process.env.ACCESS_SECRET,
}); 

client.v1
      .tweet("This tweet was written by a bot")
      .then((val) => {
         console.log(val);
         console.log("success");
      })
      .catch((err) => {
         console.log(err);
      });

Thanks in advance :)



Solution 1:[1]

You're using the twitter-api-v2 node package, and then using client.v1 which calls the v1.1 API, and you don't have access to that. Read the docs for the node library, and the error message - the answer is right there. You will need to request Elevated access to use that particular set of API calls.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Andy Piper