How to use the instagram-private-api.IgApiClient function in instagram-private-api

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 breuerfelix / jinsta / src / main.ts View on Github external
function setupClient(config: Config): IgApiClient {
	// 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;

	const client = new IgApiClient();
	if (config.proxy) client.state.proxyUrl = config.proxy;

	return client;
}
github ififfy / flipflip / src / renderer / components / configGroups / APICard.tsx View on Github external
onFinishAuthInstagram() {
    this._ig = new IgApiClient();
    this._tfa = null;
    this._ig.state.generateDevice(this.state.input1);
    this._ig.account.login(this.state.input1, this.state.input2).then((loggedInUser) => {
      // Update props
      this.props.onUpdateConfig((c) => {
        c.remoteSettings.instagramUsername = this.state.input1;
        c.remoteSettings.instagramPassword = this.state.input2;
      });
      // Update state
      this.props.onUpdateSettings((s) => {
        s.instagramUsername = this.state.input1;
        s.instagramPassword = this.state.input2;
      });
      this.setState({successSnack: "Instagram is activated"});
      this.onCloseDialog();
      this._ig = null;
github Nerixyz / instagram_mqtt / examples / push.example.ts View on Github external
(async () => {
    const ig: IgApiClientFbns = withFbns(new IgApiClient());
    ig.state.generateDevice(process.env.IG_USERNAME);

    // this will set the auth and the cookies for instagram
    await readState(ig);

    // this logs the client in
    await loginToInstagram(ig);

    // Example: listen to direct-messages
    // 'direct_v2_message' is emitted whenever anything gets sent to the user
    ig.fbns.on('direct_v2_message', logEvent('direct-message'));

    // 'push' is emitted on every push notification
    ig.fbns.on('push', logEvent('push'));
    // 'auth' is emitted whenever the auth is sent to the client
    ig.fbns.on('auth', async (auth) => {
github ififfy / flipflip / src / renderer / data / actions.ts View on Github external
const instagramImportLoop = () => {
    const state = getState();
    if (state.progressMode == PR.cancel) {
      setState({progressMode: null, progressNext: null, progressCurrent: 0});
      return;
    }
    if (ig == null) {
      ig = new IgApiClient();
      ig.state.generateDevice(state.config.remoteSettings.instagramUsername);
      ig.account.login(state.config.remoteSettings.instagramUsername, state.config.remoteSettings.instagramPassword).then((loggedInUser) => {
        ig.state.serializeCookieJar().then((cookies) => {
          session = JSON.stringify(cookies);
          const followingFeed = ig.feed.accountFollowing(loggedInUser.pk);
          followingFeed.items().then((items) => {
            processItems(items, loggedInUser.pk + "~" + followingFeed.serialize());
          }).catch((e) => {error(e);});
        }).catch((e) => {error(e);});
      }).catch((e) => {error(e);});
    } else {
      ig.state.deserializeCookieJar(JSON.parse(session)).then((data) => {
        const id = (state.progressNext as string).split("~")[0];
        const feedSession = (state.progressNext as string).split("~")[1];
        const followingFeed = ig.feed.accountFollowing(id);
        followingFeed.deserialize(feedSession);
github linkfy / Tools-for-Instagram / src / login.js View on Github external
require('dotenv').config();
let fs = require('fs');
let Bluebird = require('bluebird');
let inquirer = require('inquirer');
let Api = require('instagram-private-api');
let _ = require('lodash');
let ig = new Api.IgApiClient();
let colors = require('colors');
const low = require('lowdb');
const FileSync = require('lowdb/adapters/FileSync');
const shortid = require('shortid');


function saveCookies(cookies, state) {
	//console.log(cookies);
    //console.log(state);
    var cookiepath = "cookies/" + (process.env.IG_USERNAME).toLowerCase() + ".json";
    if(!fs.existsSync("cookies/")) {
        fs.mkdirSync("cookies/");
    }
    if(!fs.existsSync("db/")) {
        fs.mkdirSync("db/");
    }