node-twitter-api-v2
node-twitter-api-v2 copied to clipboard
[bug] ApiResponseError: Request failed with code 403 (There is a problem with API Access.)
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.
How can I solve this problem? It seems to be a general question and most people seem to have started a thread about it.
Hey Furkan, It seems like you're trying to read tweets? If so I think you have to upgrade to a paid plan