dilame / instagram-private-api

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

IgCookieNotFoundError: Cookie "ds_user_id" not found #1686

Open SpreeHertz opened 1 year ago

SpreeHertz commented 1 year ago

Error

Requirements

Description

My username and password is correct, yet I still get the error mentioned in the issue title. This is a duplicate of #997 but the issue was not properly resolved there.

Code

const fetch = require('node-fetch');
const config = require('./config.json')
const chalk = require('chalk');
const { IgApiClient } = require("instagram-private-api")
require('dotenv').config();
const ms = require('ms');

const USERNAME = "wtffspree";
const PASSWORD = process.env.instagram_password || config.instagram_password;
const currentBio = process.env.current_bio || config.current_bio;
const sentenceBeforeMentioningTrack = process.env.sentence_before_mentioning_track || config.sentence_before_mentioning_track;

const ig = new IgApiClient()
ig.state.generateDevice(USERNAME);

const response = fetch("https://api.spotify.com/v1/me/player/currently-playing?market=ES", {
        method: 'GET',
        headers: {
            'Content-Type': 'application/json',
            'Accept': 'application/json',
            'Authorization': `Bearer ${process.env.spotify_token || config.spotify_token}`,
        },
    })

const login = async () => {
    try {
        await ig.simulate.preLoginFlow()
        await ig.account.login(USERNAME, PASSWORD)
        process.nextTick(async () => await ig.simulate.postLoginFlow())
    }
    catch (err) {
        console.log(chalk.redBright('error' + " An error occured while connecting to your Instagram account:" + err))
    }
}

const main = async () => {
    try {
    const data = await response.json();
    const track = data.item.name;
    const artist = data.item.artists[0].name;
    console.log(chalk.blueBright('playing') + chalk.yellow(` ${track}`) + ` -` + chalk.yellowBright(` ${artist}`));
    login().then(await ig.account.setBiography(`${currentBio}` + `${sentenceBeforeMentioningTrack}` + ` ${track} - ${artist}`))    
    }
    catch (err) {
        login().then(await ig.account.setBiography(`${currentBio}`))
    }

}

main()
setInterval(main, ms('1m'));

Error and Output

            throw new errors_1.IgCookieNotFoundError(key);
                  ^

IgCookieNotFoundError: Cookie "ds_user_id" not found
    at State.extractCookieValue (D:\Code\currently-playing-bio\node_modules\instagram-private-api\dist\core\state.js:143:19)
    at get cookieUserId [as cookieUserId] (D:\Code\currently-playing-bio\node_modules\instagram-private-api\dist\core\state.js:127:21)
    at AccountRepository.setBiography (D:\Code\currently-playing-bio\node_modules\instagram-private-api\dist\repositories\account.repository.js:166:41)    
    at main (D:\Code\currently-playing-bio\index.js:45:39)
    at Object.<anonymous> (D:\Code\currently-playing-bio\index.js:50:1)
    at Module._compile (node:internal/modules/cjs/loader:1105:14)
    at Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
    at Module.load (node:internal/modules/cjs/loader:981:32)
    at Module._load (node:internal/modules/cjs/loader:827:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
    at node:internal/main/run_main_module:17:47
phillypro commented 1 year ago

because the serialized data is a promise...put an await on it