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

Search by username throw error #113

Open
anivire opened this issue Oct 31, 2024 · 3 comments
Open

Search by username throw error #113

anivire opened this issue Oct 31, 2024 · 3 comments

Comments

@anivire
Copy link

anivire commented Oct 31, 2024

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

@fa0311
Copy link
Owner

fa0311 commented Nov 1, 2024

The following test works fine.

test('getUserByScreenName', async () => {
logger.log('getUserByScreenName');
const client = await getClient();
const response = await client.getUserApi().getUserByScreenName({ screenName: 'elonmusk' });
printUser(response.data);
expect(response.raw.response.ok).toBe(true);
});

Can you provide source code to reproduce?

@anivire
Copy link
Author

anivire commented Nov 1, 2024

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
Copy link
Owner

fa0311 commented Nov 1, 2024

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

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

2 participants