What Could Be the Cause of the Error When Using the Twitter API for Posting Tweets?

76 views Asked by At

I am utilizing the Twitter API to make a post on Twitter.

I encountered the following error:

  Error fetching followers: ApiResponseError: Request failed with code 403
    at RequestHandlerHelper.createResponseError
  .....
  rateLimit: { limit: 1080000, remaining: 1079997, reset: 1700924172 },
  data: {
    title: 'Forbidden',
    status: 403,
    detail: 'Your client app is not configured with the appropriate oauth1 app permissions for this endpoint.',
    type: 'https://api.twitter.com/2/problems/oauth1-permissions'
  }

I generated the API keys on the Twitter Developers page:

enter image description here

enter image description here

And I am using the following code:

import { TwitterApi } from 'twitter-api-v2';

const twitterClient = new TwitterApi({
  appKey: 'Qjx6****GrD',
  appSecret: '3W7****l1w0',
  accessToken: '291****fYgm',
  accessSecret: 'Dj7H****S7E',
});

async function main() {
  try {
    await twitterClient.v2.tweet('bla').catch((err) => {
      if (!err.data.detail.includes('Tweet with duplicate content')) throw err;
    });
  } catch (error) {
    console.error('Error fetching followers:', error);
  }
}

main();

What might be the issue?

0

There are 0 answers