How to use instagram-private-api - 10 common examples

To help you get started, we’ve selected a few instagram-private-api examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github breuerfelix / jinsta / src / loop.ts View on Github external
constructor(config: Config) {
		// must be the first thing in the application start
		addLogRotate(config.workspacePath);

		// TODO check if config is valid
		if (!fs.existsSync(config.workspacePath)) fs.mkdirSync(config.workspacePath);
		// use username as seed as default
		if (!config.seed) config.seed = config.username;

		this.ig = new IgApiClient();
		if (config.proxy) this.ig.state.proxyUrl = config.proxy;

		this.config = config;
		this.session = new session(this.ig, this.config);

		if (config.likeLimit > 0) {
			// setup process exit when like limit reached
			store.pluck('imageLikes').subscribe(likes => {
				if (likes >= this.config.likeLimit) process.exit(0);
			});
		}
	}
github Nerixyz / instagram_mqtt / examples / realtime.example.ts View on Github external
(async () => {
    // this extends the IgApiClient with realtime features
    const ig: IgApiClientRealtime = withRealtime(new IgApiClient());
    // normal login
    ig.state.generateDevice(process.env.IG_USERNAME);
    await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);

    const subToLiveComments = (broadcastId) =>
        // you can add other GraphQL subs using .subscribe
        ig.realtime.graphQlSubscribe(GraphQLSubscriptions.getLiveRealtimeCommentsSubscription(broadcastId));

    // whenever something gets sent and has no event, this is called
    ig.realtime.on('receive', (topic, messages) => {
        console.log('receive', topic, messages);
    });
    ig.realtime.on('direct', logEvent('direct'));
    // this is called with a wrapper use {message} to only get the message from the wrapper
    ig.realtime.on('message', logEvent('messageWrapper'));
    // whenever something gets sent to /ig_realtime_sub and has no event, this is called
github ififfy / flipflip / src / renderer / components / player / SourceScraper.tsx View on Github external
if (item.video_versions) {
          images.push(item.video_versions[0].url);
        } else if (item.image_versions2) {
          images.push(item.image_versions2.candidates[0].url);
        }
      }
      // Strict filter won't work because instagram media needs the extra parameters on the end
      helpers.count = helpers.count + filterPathsToJustPlayable(IF.any, images, false).length;
      resolve({
        data: filterPathsToJustPlayable(filter, images, false),
        helpers: helpers,
      });
    };

    if (ig == null) {
      ig = new IgApiClient();
      ig.state.generateDevice(config.remoteSettings.instagramUsername);
      return new CancelablePromise((resolve) => {
        ig.account.login(config.remoteSettings.instagramUsername, config.remoteSettings.instagramPassword).then((loggedInUser) => {
          ig.state.serializeCookieJar().then((cookies) => {
            session = JSON.stringify(cookies);
            ig.user.getIdByUsername(getFileGroup(url)).then((id) => {
              const userFeed = ig.feed.user(id);
              userFeed.items().then((items) => {
                helpers.next = [id, userFeed.serialize()];
                processItems(items, resolve, helpers);
              }).catch((e) => {console.error(e);resolve(null)});
            }).catch((e) => {console.error(e);resolve(null)});
          }).catch((e) => {console.error(e);resolve(null)});
        }).catch((e) => {
          systemMessage(e + "\n\nVisit Settings to authorize Instagram and attempt to resolve this issue.");
          console.error(e);
github Nerixyz / instagram_mqtt / src / main.ts View on Github external
/* eslint no-console: "off" */
import { IgApiClient } from 'instagram-private-api';
import { FbnsClient } from './fbns/fbns.client';
import { RealtimeClient } from './realtime/realtime.client';
import { GraphQLSubscription, GraphQLSubscriptions } from './realtime/subscriptions/graphql.subscription';
import { Topic } from './topic';
import { ParsedMessage } from './realtime/parsers/parser';

const ig = new IgApiClient();

ig.state.generateDevice(process.env.IG_USERNAME);

(async () => {
    await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);

    const realtimeClient = new RealtimeClient(ig, [
        GraphQLSubscriptions.getAppPresenceSubscription(),
        GraphQLSubscriptions.getClientConfigUpdateSubscription(),
        GraphQLSubscriptions.getZeroProvisionSubscription(ig.state.deviceId),
        GraphQLSubscriptions.getDirectTypingSubscription(ig.state.cookieUserId),
        GraphQLSubscriptions.getAsyncAdSubscription(ig.state.cookieUserId),
    ]);
    realtimeClient.on('receive', (topic: Topic, messages: ParsedMessage[]) => {
        console.log(`${topic.path}\n${JSON.stringify(messages.map(msg => msg.data), undefined, 2)}\n`);
    });
github terkelg / ramme / src / common / api / user.js View on Github external
const getActivity = async (cursor = null) => {
  if (user) {
    try {
      let session = await loadSession(user)
      // let account = await session.getAccount()
      return new api.Request(session)
        .setMethod('GET')
        .setResource('news')
        .send()
        .then(function (json) {
          console.log(inspect(json))
          return inspect(json)
        })
    } catch (e) {
      return false
    }
  }
}
github linkfy / Tools-for-Instagram / src / login.js View on Github external
} catch (e){
            console.log(e);
            console.log("Login failed from cookie | Remove incorrect cookie".red);
            return "removeCookie";
        };
        

        //Open DB
        const adapter = new FileSync("./db/"+(process.env.IG_USERNAME).toLowerCase()+".json");
        const db = low(adapter);
        db.defaults({likes: [], follows: []}).write()
        ig.shortid = shortid;
        ig.db = db;
        
        return ig;
    }).catch(Api.IgCheckpointError, async () => {

        console.log(ig.state.checkpoint);
        await ig.challenge.auto(true); //Sms it was me
        console.log(ig.state.checkpoint); //Challenge info here
        
        let code = await inquirer.prompt([
            {
                type: 'input',
                name: 'code',
                message: 'Enter code',
            },
        ]);

        // Code is an object, lets parse the content
        code = code.code;
github linkfy / Tools-for-Instagram / src / login.js View on Github external
]);

        // Code is an object, lets parse the content
        code = code.code;
        
        let sendCode = await ig.challenge.sendSecurityCode(code);
        console.log(sendCode);
    }).catch(Api.IgLoginRequiredError, () => {
        if(hasCookies) {
            console.log("Invalid cookies");
        } else {
            // This block is not supossed to be used never (IgLoginBadPasswordError) exists
            console.log("Incorrect password");
            return "incorrectPassword";
        }
    }).catch(Api.IgLoginBadPasswordError, () => {
        console.log("Incorrect password");
        return "incorrectPassword";
    });
    // If result is not undefined we send the ig object session
    return result;
}
github linkfy / Tools-for-Instagram / src / login.js View on Github external
console.log(ig.state.checkpoint); //Challenge info here
        
        let code = await inquirer.prompt([
            {
                type: 'input',
                name: 'code',
                message: 'Enter code',
            },
        ]);

        // Code is an object, lets parse the content
        code = code.code;
        
        let sendCode = await ig.challenge.sendSecurityCode(code);
        console.log(sendCode);
    }).catch(Api.IgLoginRequiredError, () => {
        if(hasCookies) {
            console.log("Invalid cookies");
        } else {
            // This block is not supossed to be used never (IgLoginBadPasswordError) exists
            console.log("Incorrect password");
            return "incorrectPassword";
        }
    }).catch(Api.IgLoginBadPasswordError, () => {
        console.log("Incorrect password");
        return "incorrectPassword";
    });
    // If result is not undefined we send the ig object session
    return result;
}
github igdmapps / igdm / main / instagram.js View on Github external
return new Promise((resolve, reject) => {
    const needsNewThread = !thread || thread.threadId !== chatId
    if (needsNewThread) {
      thread = new Client.Feed.ThreadItems(session, chatId)
    }

    if (!needsNewThread && !thread.isMoreAvailable()) {
      // there aren't any older messages
      resolve({thread, messages: []})
    }

    thread.get().then((messages) => {
      if (needsNewThread) {
        if (thread.isMoreAvailable()) {
          // get the next 20 because the first 20 messages already were fetched with #getChat
          return thread.get().then((messages) => resolve({ thread, messages }))
        }
        // there aren't any older messages
        messages = []
      }
github igdmapps / igdm / main / instagram.js View on Github external
resolve(unfollowers);
    }

    const getUsers = (newUsers, allUsers, usersGetter, otherUsersGetter) => {
      newUsers.forEach((user) => allUsers.push(user))
      // moreAvailable maybe null. We are dodging that.
      if (usersGetter.moreAvailable === false && otherUsersGetter.moreAvailable === false){
        compare();
      } else if (usersGetter.moreAvailable !== false) {
        usersGetter.get()
          .then((users) => getUsers(users, allUsers, usersGetter, otherUsersGetter))
          .catch(reject);
      }
    }

    const followersGetter = new Client.Feed.AccountFollowers(session, accountId);
    const followingGetter = new Client.Feed.AccountFollowing(session, accountId)

    getUsers([], followers, followersGetter, followingGetter);
    getUsers([], following, followingGetter, followersGetter);
  })
}