Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

403 error when attempting to post #500

Open
campgurus opened this issue Oct 15, 2023 · 13 comments
Open

403 error when attempting to post #500

campgurus opened this issue Oct 15, 2023 · 13 comments

Comments

@campgurus
Copy link

Note: For questions about how to use an endpoint, or problems related to Twitter API than the lib itself, please use the GitHub Discussions instead of opening a new issue.

Trying to create a Twitter bot in Node.js. Getting a 403 error on the request.

here is the full error trace:

ApiResponseError: Request failed with code 403
    at RequestHandlerHelper.createResponseError (/Users/darius/Code/flumly-bot/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:104:16)
    at RequestHandlerHelper.onResponseEndHandler (/Users/darius/Code/flumly-bot/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:262:25)
    at IncomingMessage.emit (node:events:525:35)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  error: true,
  type: 'response',
  code: 403,
  headers: {
    perf: '7626143928',
    'content-type': 'application/problem+json',
    'cache-control': 'no-cache, no-store, max-age=0',
    'content-length': '297',
    'x-transaction-id': '210b23a7a4b6ca3c',
    'x-response-time': '2',
    'x-connection-hash': '5a7ce993b8ccc4f087354980c7c7c510c2ded8b91ab6000756d91ded7cd7c16c',
    date: 'Sun, 15 Oct 2023 11:33:38 GMT',
    server: 'tsa_b',
    connection: 'close'
  },
  rateLimit: undefined,
  data: {
    title: 'Unsupported Authentication',
    detail: 'Authenticating with Unknown is forbidden for this endpoint.  Supported authentication types are [OAuth 1.0a User Context, OAuth 2.0 User Context].',
    type: 'https://api.twitter.com/2/problems/unsupported-authentication',
    status: 403
  }
}

here is my client config:

const { TwitterApi } = require("twitter-api-v2");

const client = new TwitterApi({
    appKey: process.env.TWITTER_API_KEY,
    appSecret: process.env.TWITTER_API_SECRET,
    accessToken: process.env.TWITTER_ACCESS_TOKEN,
    accessSecret: process.env.TWITTER_ACCESS_SECRET,
});

const bearer = new TwitterApi(process.env.TWITTER_BEARER_TOKEN);

const twitterClient = client.readWrite;
const twitterBearer = bearer.readOnly;

module.exports = { twitterClient, twitterBearer };

and index.js

require("dotenv").config({ path: __dirname + "/.env" });
const { twitterClient } = require("./twitterClient.js")
const tweet = async () => {
    try {
        await twitterClient.v2.tweet("Hello world!");
    } catch (e) {
        console.log(e)
    }
}

tweet();
@mwilkinson22
Copy link

This often happens when a Twitter App isn't a member of a project. Head to your projects & apps overview page - if your app appears under "Standalone Apps" you'll need to create a project and assign the app to it

@campgurus
Copy link
Author

The App is within a project. screenshot:

Screenshot 2023-10-20 at 6 05 33 AM

@mwilkinson22
Copy link

Ah sorry - I'm not affiliated with this library but I'd just had that problem myself recently, was a bit of a shot in the dark!

On closer inspection it looks like a basic authentication issue - what happens if you call twitterClient.v1.verifyCredentials()?

@campgurus
Copy link
Author

No worries grateful for the help. Meanwhile, I think I don't have access to v1:

ApiResponseError: Request failed with code 403 - Your credentials do not allow access to this resource (Twitter code 37)
    at RequestHandlerHelper.createResponseError (/Users/darius/Code/flumly-bot/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:104:16)
    at RequestHandlerHelper.onResponseEndHandler (/Users/darius/Code/flumly-bot/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:262:25)
    at Gunzip.emit (node:events:513:28)
    at endReadableNT (node:internal/streams/readable:1359:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  error: true,
  type: 'response',
  code: 403,
  headers: {
    date: 'Fri, 20 Oct 2023 11:17:20 UTC',
    perf: '7626143928',
    server: 'tsa_b',
    'set-cookie': [
      'guest_id_marketing=v1%3A169780064063369209; Max-Age=63072000; Expires=Sun, 19 Oct 2025 11:17:20 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'guest_id_ads=v1%3A169780064063369209; Max-Age=63072000; Expires=Sun, 19 Oct 2025 11:17:20 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'personalization_id="v1_kxZM5/LOaZoQG0/8kpgZuQ=="; Max-Age=63072000; Expires=Sun, 19 Oct 2025 11:17:20 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'guest_id=v1%3A169780064063369209; Max-Age=63072000; Expires=Sun, 19 Oct 2025 11:17:20 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None'
    ],
    'content-type': 'application/json;charset=utf-8',
    'cache-control': 'no-cache, no-store, max-age=0',
    'x-transaction-id': 'd3171bde74e8da0b',
    'strict-transport-security': 'max-age=631138519',
    'content-encoding': 'gzip',
    'content-length': '106',
    'x-response-time': '4',
    'x-connection-hash': 'c5163e55a1a73330ff02f2aae694e224e1645f5e29dbd0558c0eb2cb0af76eff',
    connection: 'close'
  },
  rateLimit: undefined,
  data: { errors: [ [Object] ] },
  errors: [
    {
      message: 'Your credentials do not allow access to this resource',
      code: 37
    }
  ]

@sir-kain
Copy link

sir-kain commented Oct 28, 2023

Facing the same issue here

EDIT:
I resolved the issue by configuring the authentication settings and subsequently generating new API and secret keys

image

@arunlz
Copy link

arunlz commented Nov 8, 2023

image
I'm also facing the same 403 error.

@wavecatch2020s
Copy link

I am getting the same error when I try to upload Media.
Did anyone had any success with this error?

@Prottoy2938
Copy link

same error here

@solojungle
Copy link
Contributor

I am getting the same error when I try to upload Media. Did anyone had any success with this error?

Did you ever figure it out? Having the same issue here 😅

@cheskoxd
Copy link

I am getting the same error when I try to upload Media. Did anyone had any success with this error?

Did you ever figure it out? Having the same issue here 😅

that makes two of us :(

@solojungle
Copy link
Contributor

I am getting the same error when I try to upload Media. Did anyone had any success with this error?

Did you ever figure it out? Having the same issue here 😅

that makes two of us :(

@cheskoxd my solution is here!

#416 (comment)

@cheskoxd
Copy link

Thanks!!

@whenmoon
Copy link

whenmoon commented Jul 1, 2024

Facing the same issue here

EDIT: I resolved the issue by configuring the authentication settings and subsequently generating new API and secret keys

image

Thanks @sir-kain I was also able to fix this issue simply by regenerating keys.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants