async login() {
        try {
            let homepage = await this.fetchHomepage();
            this.debugLog("Fetching homepage..");
            let parsedConfig = this.parseSharedData(homepage);
            this.debugLog("Parsing..");
            if (parsedConfig === -1) {
                throw new Error("Failed to parse shared data..");
            }

            if (!homepage.includes(this.username)) {
                this.debugLog("Logging in for the first time..");
                let options = Object.assign(this.defaultRequestOptions);
                options["url"] = "https://www.instagram.com/accounts/login/ajax/";
                this.rolloutHash = parsedConfig["rollout_hash"];
                this.setRolloutHash();
                this.csrfToken = parsedConfig["config"]["csrf_token"];
                options["headers"]["X-CSRFToken"] = this.csrfToken;
                this.debugLog(`Login Token: ${this.csrfToken}`);
                options["form"] = { "username": this.username, "password": this.password };
                this.debugLog("Trying to login..");
                let submitLogin = await this.fetchPage({
                    options,
                    isPost: true
                });

                let result = JSON.parse(submitLogin);
                this._userId = result["userId"];
                if (typeof result["authenticated"] === "undefined" || !result["authenticated"]) {
                    throw new Error(result);
                }

                homepage = await this.fetchHomepage();
                parsedConfig = this.parseSharedData(homepage);
            }

            this.csrfToken = parsedConfig["config"]["csrf_token"];
            this._userId = parsedConfig["config"]["viewerId"];
            this.debugLog(`Final Token: ${this.csrfToken}`);
            return this.csrfToken;
        } catch (error) {
            console.error(`_login ${error}`);
            throw new Error(error);
        }
    }
/**
     *
     * Login to account using username & password given.
     * @memberof Fusia
     */
Login to account using username & password given.
@memberof Fusia
Login to account using username & password given . @memberof Fusia
async login() {
        try {
            let homepage = await this.fetchHomepage();
            this.debugLog("Fetching homepage..");
            let parsedConfig = this.parseSharedData(homepage);
            this.debugLog("Parsing..");
            if (parsedConfig === -1) {
                throw new Error("Failed to parse shared data..");
            }
            if (!homepage.includes(this.username)) {
                this.debugLog("Logging in for the first time..");
                let options = Object.assign(this.defaultRequestOptions);
                options["url"] = "https://www.instagram.com/accounts/login/ajax/";
                this.rolloutHash = parsedConfig["rollout_hash"];
                this.setRolloutHash();
                this.csrfToken = parsedConfig["config"]["csrf_token"];
                options["headers"]["X-CSRFToken"] = this.csrfToken;
                this.debugLog(`Login Token: ${this.csrfToken}`);
                options["form"] = { "username": this.username, "password": this.password };
                this.debugLog("Trying to login..");
                let submitLogin = await this.fetchPage({
                    options,
                    isPost: true
                });
                let result = JSON.parse(submitLogin);
                this._userId = result["userId"];
                if (typeof result["authenticated"] === "undefined" || !result["authenticated"]) {
                    throw new Error(result);
                }
                homepage = await this.fetchHomepage();
                parsedConfig = this.parseSharedData(homepage);
            }
            this.csrfToken = parsedConfig["config"]["csrf_token"];
            this._userId = parsedConfig["config"]["viewerId"];
            this.debugLog(`Final Token: ${this.csrfToken}`);
            return this.csrfToken;
        } catch (error) {
            console.error(`_login ${error}`);
            throw new Error(error);
        }
    }
async login ( ) { try { let homepage = await this . fetchHomepage ( ) ; this . debugLog ( "Fetching homepage.." ) ; let parsedConfig = this . parseSharedData ( homepage ) ; this . debugLog ( "Parsing.." ) ; if ( parsedConfig === - 1 ) { throw new Error ( "Failed to parse shared data.." ) ; } if ( ! homepage . includes ( this . username ) ) { this . debugLog ( "Logging in for the first time.." ) ; let options = Object . assign ( this . defaultRequestOptions ) ; options [ "url" ] = "https://www.instagram.com/accounts/login/ajax/" ; this . rolloutHash = parsedConfig [ "rollout_hash" ] ; this . setRolloutHash ( ) ; this . csrfToken = parsedConfig [ "config" ] [ "csrf_token" ] ; options [ "headers" ] [ "X-CSRFToken" ] = this . csrfToken ; this . debugLog ( ` ${ this . csrfToken } ` ) ; options [ "form" ] = { "username" : this . username , "password" : this . password } ; this . debugLog ( "Trying to login.." ) ; let submitLogin = await this . fetchPage ( { options , isPost : true } ) ; let result = JSON . parse ( submitLogin ) ; this . _userId = result [ "userId" ] ; if ( typeof result [ "authenticated" ] === "undefined" || ! result [ "authenticated" ] ) { throw new Error ( result ) ; } homepage = await this . fetchHomepage ( ) ; parsedConfig = this . parseSharedData ( homepage ) ; } this . csrfToken = parsedConfig [ "config" ] [ "csrf_token" ] ; this . _userId = parsedConfig [ "config" ] [ "viewerId" ] ; this . debugLog ( ` ${ this . csrfToken } ` ) ; return this . csrfToken ; } catch ( error ) { console . error ( ` ${ error } ` ) ; throw new Error ( error ) ; } }
Login to account using username & password given.
Login to account using username & password given .