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

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 ??? #487

Open
rodrigograca31 opened this issue Jun 21, 2023 · 8 comments

Comments

@rodrigograca31
Copy link

Describe the bug

since a few weeks ago i've been getting this error... no code was changed.
I've tried everything I know... reinstalled the lib, renewed my token, searched google/github, tried changing code...
seems like others are having similar problems lately

my code just tries to obtain all new tweets with a given keyword...

         "code": 403,
        "error": {
            "client_id": "27347717",
            "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"
        },

To Reproduce
Please indicate all steps that lead to this bug:

  1. npm i twitter-api-v2
  2. nano twitter.js
  3. paste code
  4. run it
// ####### TWITTER code
const TOKEN =
	"TOKEN";

import {
	ETwitterStreamEvent,
	TweetStream,
	TwitterApi,
	ETwitterApiError,
	ApiRequestError,
} from "twitter-api-v2";

// Instanciate with desired auth type (here's Bearer v2 auth)
const twitterClient = new TwitterApi(TOKEN);

// async function
async function getTweets() {
	// // Get and delete old rules if needed
	// const rules = await twitterClient.v2.streamRules();
	// if (rules.data?.length) {
	// 	await twitterClient.v2.updateStreamRules({
	// 		delete: { ids: rules.data.map((rule) => rule.id) },
	// 	});
	// }

	// // Add our rules
	// await twitterClient.v2.updateStreamRules({
	 //	add: [{ value: "JavaScript" }, { value: "NodeJS" }],
//	 });

	const stream = await twitterClient.v2.searchStream({
		"tweet.fields": ["public_metrics", "author_id"],
		expansions: ["author_id"],
		autoConnect: false, // Note the autoConnect: false
	});

	try {
		// Options are directly given in .connect() method
		await stream.connect({
			autoReconnect: true,
			autoReconnectRetries: Infinity,
		});
	} catch (error) {
		console.log(
			"Unable to establish the first connection. Auto-reconnect will be fired soon."
		);
		console.log(error);
	}

	stream.on(ETwitterStreamEvent.Data, (tweet) => {
		console.log(tweet);
		// @ts-ignore
		const username = tweet.includes.users[0].username;

		console.log(tweet);
		console.log("TWITTER: https://twitter.com/", username);
	});
	
	console.log("aa")
}

getTweets();

Expected behavior
to work and get the tweets

Version

  • Node.js version: v16.15.1
  • Lib version: twitter-api-v2@1.15.0
  • OS (especially if you use Windows) Linux

Additional context
Add any other context about the problem here.

@rodrigograca31
Copy link
Author

Small update.....
I think twitter moved the tweets lookup to paid...
so now unless you pay 100$ per month you CANT lookup tweets in real time... 🤦 😢

https://stackoverflow.com/questions/76100129/problem-with-keys-and-tokens-when-making-requests-to-postman-via-the-twitter-api

@timb-103
Copy link

Have you checked your dev portal to see if your app has moved to a "standalone app"? There's an issue over the last week or two where apps get moved to standalone for some reason. If you move it back, it will work again.

@rodrigograca31
Copy link
Author

yeah! even re-created the project and app!

@medsghiri
Copy link

@rodrigograca31 did you find a solution? I'm having the same problem the app is not standalone and I'm having the same problem on a free plan and even the basic one

@rodrigograca31
Copy link
Author

nope. i think Elon just f'ed it up forever....

i had such cool implementation.... it would trigger something physical in real time when people tweeted something....
it will probably not work ever again.. and other social networks dont offer this type of real time... maybe Threads will? 🤔🤔🤔

@rakpawel
Copy link

@rodrigograca31 Have you got it working? I'm trying to get tweets using await twitterClient.v2.homeTimeline(); but getting the same error. My app is for sure assigned to the Project.

@rodrigograca31
Copy link
Author

I didnt I gave up, they broke/limited the API forever so I wont waste time with it.
twitter/x is prolly gonna die over time

@npomfret
Copy link

Did anyone get this working? I'm using the $100 version of the subscription, but when I tried to call updateStreamRules and connecting using new TwitterApi(bearerToken), but it just craps out:

        {
            "type": "response",
            "code": 403,
            "error": {
                "client_id": "xxx",
                "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"
        }...

Can't make sense of the documentation.

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

5 participants