dilame / instagram-private-api

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

Is there a way to get account posts count? #1527

Open againksy opened 3 years ago

againksy commented 3 years ago

Can't find in the documentation. Which instance is keeping this info? How to find the all posts for specific user count? Also most links in the repository not wokring.

keharv commented 3 years ago

Here is a working example of how to obtain a user's post count:

Code

//requires for instagram
/* tslint:disable:no-console */
var {IgApiClient} =  require('instagram-private-api');
var { get } = require('request-promise'); // request is already declared as a dependency of the library

const fs = require('fs');
bot = async () => {
    //instagram credentials
    const igUsername = "";
    const igPassword = "";
    //instagram session handling
    function saveSession(data) {
        fs.writeFileSync('./igSession.dat', JSON.stringify(data));
        return data;
    }

    function checkSession() {
        return fs.existsSync('./igSession.dat');
    }

    function loadSession() {
        return JSON.parse(fs.readFileSync('./igSession.dat').toString());
    }
    const ig = new IgApiClient();
    ig.state.generateDevice(igUsername);
    ig.request.end$.subscribe(async () => {
        const serialized = await ig.state.serialize();
        delete serialized.constants; // this deletes the version info, so you'll always use the version provided by the library
        saveSession(serialized);
    });
    if (checkSession()) {
        // import state accepts both a string as well as an object
        // the string should be a JSON object
        await ig.state.deserialize(loadSession());
    }
    const auth = await ig.account.login(igUsername, igPassword);

    const userID = await ig.user.getIdByUsername('google');
    const userInfo = await ig.user.info(userID);
    console.log(userInfo.media_count);
}
bot();