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

[bug] ApiResponseError: Request failed with code 403 (There is a problem with API Access.) #530

Open
furkancelik opened this issue May 10, 2024 · 1 comment

Comments

@furkancelik
Copy link

I installed the package as specified and my code is as follows;

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


const client = new TwitterApi({
  appKey: "XXX",
  appSecret: "XXX",
  accessToken: "XXX",
  accessSecret: "XXX",
});



const tweetId = "XXX";
const readOnlyClient = client.readWrite;

const user = await readOnlyClient.v2.userByUsername("XXX");
const tweet = readOnlyClient.v2.singleTweet(tweetId);

This code gives error like here.


/x/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:104
        return new types_1.ApiResponseError(errorString, {
               ^
ApiResponseError: Request failed with code 403
    at RequestHandlerHelper.createResponseError (/Users/furkancelik/Desktop/x/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:104:16)
    at RequestHandlerHelper.onResponseEndHandler (/Users/furkancelik/Desktop/x/node_modules/twitter-api-v2/dist/cjs/client-mixins/request-handler.helper.js:262:25)
    at Gunzip.emit (node:events:518:28)
    at endReadableNT (node:internal/streams/readable:1696:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  error: true,
  type: 'response',
  code: 403,
  headers: {
    date: 'Fri, 10 May 2024 14:03:37 UTC',
    perf: '7402827104',
    server: 'tsa_o',
    'set-cookie': [
      'guest_id_marketing=v1%3A171534981756431045; Max-Age=63072000; Expires=Sun, 10 May 2026 14:03:37 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'guest_id_ads=v1%3A171534981756431045; Max-Age=63072000; Expires=Sun, 10 May 2026 14:03:37 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'personalization_id="v1_eOItLL+PePEv+fUcMe8WUQ=="; Max-Age=63072000; Expires=Sun, 10 May 2026 14:03:37 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None',
      'guest_id=v1%3A171534981756431045; Max-Age=63072000; Expires=Sun, 10 May 2026 14:03:37 GMT; Path=/; Domain=.twitter.com; Secure; SameSite=None'
    ],
    'api-version': '2.97',
    'content-type': 'application/json; charset=utf-8',
    'cache-control': 'no-cache, no-store, max-age=0',
    'content-length': '327',
    'x-access-level': 'read-write-directmessages',
    'x-frame-options': 'SAMEORIGIN',
    'content-encoding': 'gzip',
    'x-transaction-id': '4a2484f02bd76ede',
    'x-xss-protection': '0',
    'x-rate-limit-limit': '1200000',
    'x-rate-limit-reset': '1715350717',
    'content-disposition': 'attachment; filename=json.json',
    'x-content-type-options': 'nosniff',
    'x-rate-limit-remaining': '1199999',
    'strict-transport-security': 'max-age=631138519',
    'x-response-time': '115',
    'x-connection-hash': '20230d47ef1223e4a991e90c59f28d32e6d8a2536faa3b07ddb0da2e4b59158b'
  },
  rateLimit: { limit: 1200000, remaining: 1199999, reset: 1715350717 },
  data: {
    client_id: '28764886',
    detail: 'When authenticating requests to the Twitter API v2 endpoints, you must use keys and tokens from a Twitter developer App that is attached to a Project. You can create a project via the developer portal.',
    registration_url: 'https://developer.twitter.com/en/docs/projects/overview',
    title: 'Client Forbidden',
    required_enrollment: 'Appropriate Level of API Access',
    reason: 'client-not-enrolled',
    type: 'https://api.twitter.com/2/problems/client-forbidden'
  }
}

Node.js v20.11.1

On the developer screen, the project is created and connected, its visuals are as here;
I get the same error when I try with Bearer Token or API Scret Key.

1 2 3 4

How can I solve this problem? It seems to be a general question and most people seem to have started a thread about it.

@solojungle
Copy link
Contributor

Screenshot 2024-05-13 at 11 48 40 AM

Hey Furkan,
It seems like you're trying to read tweets? If so I think you have to upgrade to a paid plan

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

2 participants