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');
}
}
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