PLhery / node-twitter-api-v2

Strongly typed, full-featured, light, versatile yet powerful Twitter API v1.1 and v2 client for Node.js.
https://www.npmjs.com/package/twitter-api-v2
Apache License 2.0
1.31k stars 181 forks source link

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 1 year ago

rodrigograca31 commented 1 year ago

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

Additional context Add any other context about the problem here.

rodrigograca31 commented 1 year ago

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... :facepalm: :cry:

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

timb-103 commented 1 year ago

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 commented 1 year ago

yeah! even re-created the project and app!

medsghiri commented 1 year ago

@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 commented 1 year ago

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 commented 11 months ago

@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 commented 11 months ago

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 commented 9 months ago

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.

huojiecs110 commented 5 days ago

I felt that the official API was too difficult to use... and the basic version was too restrictive... so I later used a third-party service... which felt much cheaper than the official one, such as http:// twitter丶utools丶me