fa0311 / twitter-openapi-typescript

Implementation of Twitter internal API (Twitter graphql API) in TypeScript
https://www.npmjs.com/package/twitter-openapi-typescript
Other
78 stars 11 forks source link

Search by username throw error #113

Open anivire opened 4 weeks ago

anivire commented 4 weeks ago

Searching by any username returns error (Response returned an error code)

fa0311 commented 3 weeks ago

The following test works fine.

https://github.com/fa0311/twitter-openapi-typescript/blob/fb626993ee79a5fded12c215fcdf03d2c35ae9a3/twitter-openapi-typescript/test/api/userApi.test.ts#L4-L10

Can you provide source code to reproduce?

anivire commented 3 weeks ago

Hmm, for some reason today all working good with same code

export class FetchServices {
  private readonly scraper = new Scraper();
  private readonly api = new TwitterOpenApi();

  async getTwitterProfile(username: string): Promise<{
    username: string;
    name?: string;
    followersCount: number;
    tweetsCount: number;
    images: {
      avatar: string;
      banner?: string;
    };
  } | null> {
    const twitterClient = await this.api.getGuestClient();
    const r = await twitterClient
      .getUserApi()
      .getUserByScreenName({ screenName: username });

    if (r && r.data && r.data.user) {
      return {
        username: r.data.user.legacy.screenName,
        name: r.data.user.legacy.name || undefined,
        followersCount: r.data.user.legacy.normalFollowersCount || 0,
        tweetsCount: r.data.user.legacy.statusesCount || 0,
        images: {
          avatar: r.data.user.legacy.profileImageUrlHttps.replace(
            '_normal',
            ''
          ),
          banner: r.data.user.legacy.profileBannerUrl,
        },
      };
    }

    return null;
  }
}
fa0311 commented 3 weeks ago

Twitter's anti-spam system gets frequent updates, so maybe that's why.