dilame / instagram-private-api

NodeJS Instagram private API SDK. Written in TypeScript.
MIT License
5.99k stars 1.14k forks source link

Getting a scraping warning from instagram. #1694

Open rohitpotato opened 1 year ago

rohitpotato commented 1 year ago

Getting a scraping warning from Instagram. Permanent ban / account disabled warning.

Notes

Form

Put an [x] if you meet the condition, else leave [ ].

Question

I am using the code below to use this library to update my bio via a nodejs and TS setup. I just got a scraping warning from Instagram which said to stop doing this to avoid my account being permanently banned.

Is there an issue with which I am using the library to log in? **I am following one of the examples to save the session in a file to avoid logging in repeatedly, as seen in the code below. What can I do to avoid getting banned? I plan to update my bio via a corn job every few minutes.

Code

class InstagramService {
  private client: IgApiClient;
  private cookiePath = path.resolve(process.cwd(), './src/config');
  constructor() {
    this.client = new IgApiClient();
    this.client.state.generateDevice(AppConfig.IG_USERNAME!);
    this.client.request.end$.subscribe(async () => {
      const serialized = await this.client.state.serialize();
      delete serialized.constants; // this deletes the version info, so you'll always use the version provided by the library
      await this.saveToken(serialized);
    });
  }

  private async saveToken(token: any): Promise<Result<boolean>> {
    const tokenWriteOrError = await FileUtils.writeFile(
      `${this.cookiePath}/Kookie.txt`,
      JSON.stringify(token),
      'utf-8',
    );
    if (tokenWriteOrError.isFailure) {
      return Result.fail(tokenWriteOrError.error);
    }
    return Result.ok(true);
  }

  private async getToken() {
    const doesFileExist = await FileUtils.exists(`${this.cookiePath}`);
    if (doesFileExist.isFailure) {
      return Result.ok(null);
    }
    if (doesFileExist.getValue()) {
      const tokenGetOrError = await FileUtils.readFile({
        path: `${this.cookiePath}/Kookie.txt`,
      });
      if (tokenGetOrError.isFailure) {
        return Result.fail(tokenGetOrError.error);
      }
      if (!tokenGetOrError.getValue()) {
        return Result.ok(null);
      }
      return Result.ok(JSON.parse(tokenGetOrError.getValue()));
    }
    return Result.ok(null);
  }

  public async login(): Promise<Result<void>> {
    const tokenOrError = await this.getToken();
    if (tokenOrError.isFailure) {
      return Result.fail(tokenOrError.error);
    }
    const token = tokenOrError.getValue();
    if (token) {
      await this.client.state.deserialize(token);
    }
    try {
      await this.client.account.login(
        AppConfig.IG_USERNAME!,
        AppConfig.IG_PASSWORD!,
      );
      return Result.ok();
    } catch (err) {
      console.log(err);
      return Result.fail({
        code: 'LOGIN_FAILED',
        message: 'login_failed',
      });
    }
  }

  public async updateBio() {
    await this.client.account.setBiography('uncomfortably numb');
  }
}
sunmasters commented 1 year ago

This repo uses old android device configuration. may be that is the issue

dadodasyra commented 1 year ago

Got the same

netojose commented 1 month ago

Got the same. 2 accounts warning/banned just while testing