How to use the instagram-private-api.V1.CookieFileStorage 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 soixantecircuits / altruist / actions / instagram.js View on Github external
const path = require('path')
const Client = require('instagram-private-api').V1

const settings = require('../src/lib/settings').actions.instagram
const cookiePath = path.join('/tmp', settings.account + '.json')

var device = new Client.Device(settings.account)
var storage = new Client.CookieFileStorage(cookiePath)

module.exports = {
  run: (options) => {
    return new Promise((resolve, reject) => {
      if (options.media === undefined || options.media === '') {
        return reject(new Error(JSON.stringify({
          err: 'invalid request',
          details: 'Error: No media in request'
        })))
      }

      Client.Session.create(device, storage, settings.account, settings.password)
        .then((session) => {
          Client.Upload.photo(session, options.media)
            .then((upload) => {
              console.log('Uploading ' + path.basename(options.media))
github terkelg / ramme / src / common / api / user.js View on Github external
const loadSession = async user => {
  let path = utils.buildPath(user.hash)
  let device = new api.Device(user.username)
  let storage = new api.CookieFileStorage(path)
  if (storage) {
    return new api.Session(device, storage)
  } else {
    let file = await createSessionFile(user)
    if (file) console.log('Session File Created')
    return false
  }
}
github terkelg / ramme / src / common / api / user.js View on Github external
const createSession = async (user, password) => {
  let path = utils.buildPath(user.hash)
  let device = new api.Device(user.username)
  let storage = new api.CookieFileStorage(path)
  if (storage) {
    try {
      let conn = await api.Session.create(device, storage, user.username, password)
      return conn
    } catch (e) {
      return e
    }
  } else {
    try {
      let file = await createSessionFile(user)
      if (!file) {
        console.log('error')
      }
      return false
    } catch (e) {
      console.log('here', e)
github mathdroid / igdm-cli / index.js View on Github external
` argument must be a number. Instead it's a ${typeof argv.interval}`
    );

  let _username;
  if (!argv.username) {
    const { username } = await inquirer.prompt({
      name: "username",
      message: "Instagram Username: "
    });
    _username = username;
  } else {
    _username = argv.username;
  }

  device = new Client.Device(_username);
  storage = new Client.CookieFileStorage(
    __dirname + `/ig-cookie.${_username}.json`
  );

  let _password;
  if (!argv.password) {
    const { password } = await inquirer.prompt({
      name: "password",
      message: "Instagram password: ",
      type: "password"
    });
    _password = password;
  } else {
    _password = argv.password;
  }

  const loginSpinner = ora(`Logging in as ${_username}`).start();
github terkelg / ramme / src / common / api / media.js View on Github external
const loadSession = user => {
  let path = utils.buildPath(user.hash)
  let device = new api.Device(user.username)
  let storage = new api.CookieFileStorage(path)
  return new api.Session(device, storage)
}
github mathdroid / igdm-cli / src / index.js View on Github external
};

  let _username;
  if (!argv.username) {
    const { username } = await inquirer.prompt({
      name: "username",
      message: "Instagram Username: "
    });
    _username = username;
  } else {
    _username = argv.username;
  }

  device = new Client.Device(`instagram.com/${_username}`);
  storage = argv.persist
    ? new Client.CookieFileStorage(
        __dirname + ("/ig-cookie." + _username + ".json")
      )
    : new Client.CookieMemoryStorage();

  let _password;
  if (!argv.password) {
    const { password } = await inquirer.prompt({
      name: "password",
      message: "Instagram password: ",
      type: "password"
    });
    _password = password;
  } else {
    _password = argv.password;
  }
github RemeJuan / social-automator / src / helpers / instagram.js View on Github external
const config = require('../config');
const findandLikeTag = require('./like-insta');
const findAndCommentTag = require('./comment-insta');

const { user, pass } = config.igauth;

const Client = require('instagram-private-api').V1;
const device = new Client.Device(user);
const storage = new Client.CookieFileStorage(`${global.base}/cookies/${user}.json`);
let session;

function createSession() {
  if(!session) {
    return Client.Session.create(device, storage, user, pass)
      .then(ses => {
        session = ses;
        return session;
      });
  }

  return Promise.resolve(session);
}

function likeOrCommentInsta() {
  const rand = (Math.random() * 10);
github igdmapps / igdm / main / utils.js View on Github external
const getCookieStorage = (filePath) => {
  let storage;
  let username;

  if (canUseFileStorage()) {
    if (!filePath && (username = guessUsername())) {
      filePath = `${username}.json`
    }

    if (filePath) storage = new Client.CookieFileStorage(`${buildAndGetStoragePath()}/${filePath}`);
  } else {
    storage = new Client.CookieMemoryStorage();
  }

  return storage;
}