node-twitter-api-v2 icon indicating copy to clipboard operation
node-twitter-api-v2 copied to clipboard

[bug] Get user followings not working with Basic subscription

Open artemosuskyi opened this issue 1 year ago • 1 comments

Here's my code snippet to do the user following fetching

public async checkUserFollows(
    currentUser: CurrentUserDto,
    { code, codeVerifier }: TwitterCodeBodyDto
  ) {
    const { accessToken } =
      await this.twitterAuthClient.loginWithOAuth2({
        code,
        codeVerifier,
        redirectUri: 'http://localhost:3005',
      });

    const user = await this.userService.findUserByEmail(
      currentUser.email
    );

    const res = await new TwitterApi(accessToken).v2.following(
      user.twitterId
    );

    return res;

    // const data = await fetch(
    //   `https://api.twitter.com/2/users/${user.twitterId}/following`,
    //   {
    //     method: 'GET',
    //     headers: {
    //       Authorization: `Bearer <bearer_token_from_dashboard/oauth2_access_token_from_above>`,
    //     },
    //   }
    // ).then((res) => res.json());
    //
    // return data;
  }

What I tried so far:

  • Instantiating TwitterApi with app/app+access secret keys
  • Fetching directly with OAuth2 access token in headers
  • Fetching directly with project bearer token in headers
  • Regenerating all tokens/secrets and redoing points above

My thought is there is something wrong with Twitter API, but if I miss something else, please tell me

artemosuskyi avatar Dec 11 '23 13:12 artemosuskyi

Hey, Artem! I've also struggled with this issue, and unfortunately, it is impossible without the Twitter Enterprise API subscription. https://devcommunity.x.com/t/getting-all-followers-of-an-account/214611

OlehSych avatar May 13 '24 14:05 OlehSych