Code Monkey home page Code Monkey logo

Comments (3)

dhillon2325 avatar dhillon2325 commented on June 5, 2024

When I try and use

/* Express */
var express = require('express');
var path = require('path');
var app = express();
app.use(express.static(path.join(__dirname, 'public')));

app.get('/', function (req, res) {
    res.render("./index.html");
});

app.get('/view', function (req, res) {
    //res.render("./index.html");

    res.send("<h1>Messages</h1>" + + "<br></br> <a href='http://localhost:3000/view/'>Reload..</a>"));
    getDMS();
});

app.get('/dm', function (req, res) {
  res.send("Sent to " + req.query['user'] + " as " + req.query['text'] 
    + "<br></br> <a href='http://localhost:3000/view/'>View this conversation..</a>")
    sendDM(req.query['user'], req.query['text']);
});

app.listen(3000, function () {
  console.log('Example app listening on port 3000!');
});


/* Instagram API */
var PrivateAPI = require('instagram-private-api');
function sendDM(user, text) {
    var Client = PrivateAPI.Client.V1;
    var device = new Client.Device('SAMSUNG_GALAXY_S2', 'n0tabot');
    var cookiePath = './cookies/n0tabot.json';
    var session = new Client.Session(device, cookiePath);
    var promise = Client.Session.create(device, cookiePath, 'n0tabot', 'dhillon');
    promise.then(function(sessionInstance) {
        // Search for the User
        Client.Account.searchForUser(session, user)
         .then(function(accountInstance) {
            var userId = accountInstance.id;
            // Send a DM
            Client.Thread.configureText(session, userId, text)
             .then(function(threads) {
                var thread = threads[0];
                //thread.broadcastText(text);
                return thread.items; // -> see conversation
            });
         });
    });
}

function getDMS() {
    var ClientProxy = PrivateAPI.ProxyClient.V1;
    var server = new ClientProxy.Server('0.0.0.0', '8080', '8888');
    var session = new ClientProxy.Session(server);
    session.create('n0tabot', 'dhillon')
        .then(function(session) {
             ClientProxy.Thread.subscribeAll(session, function(thread){
                   // this -> socket connection
                   console.log(thread, "thread change");
              })
    });
}

I get this in the Terminal.app:
Request Error RequestError: Error: unable to get local issuer certificate
at new RequestError (/Users/dhillon/Desktop/NodeJS/InstagramApp/node_modules/request-promise/lib/errors.js:11:15)
at Request.RP$callback as _callback
at self.callback (/Users/dhillon/Desktop/NodeJS/InstagramApp/node_modules/request/request.js:187:22)
at emitOne (events.js:96:13)
at Request.emit (events.js:188:7)
at Request.onRequestError (/Users/dhillon/Desktop/NodeJS/InstagramApp/node_modules/request/request.js:813:8)
at emitOne (events.js:96:13)
at ClientRequest.emit (events.js:188:7)
at TLSSocket.socketErrorListener (_http_client.js:308:9)
at emitOne (events.js:96:13)
at TLSSocket.emit (events.js:188:7)
at emitErrorNT (net.js:1272:8)
at _combinedTickCallback (internal/process/next_tick.js:74:11)
at process._tickCallback (internal/process/next_tick.js:98:9)
Unhandled rejection Error: store does not support getAllCookies and cannot be serialized

from instagram-private-api.

huttarichard avatar huttarichard commented on June 5, 2024

@dhillon2325 not sure what problem with certificate is all about, but based on previous issue, you were able to reach endpoint, not sure what change. Anyway, if you want to do some development in node.js learn first. No more type of issues "I don't know how to make app..". Go to learn, learn how to build realtime apps in node and how to async programming. After you will be done, you can try this. Questions about node development forward to stackoverflow.com

/* Express */
var express = require('express');
var path = require('path');
var app = express();
var Promise = require('bluebird');

var EXPRESS_APP = 3000;
var PROXY_APP = 8080;
var PROXY_SOCKET = 8888;

app.use(express.static(path.join(__dirname, 'public')));

app.get('/threads', function (req, res) {
    getThreads().then(function(threads) {
       res.json(threads.map(function(t){return t.params}));
    })
});

app.get('/threads/:thread', function(req, res) {
    getThread(req.params.thread).then(function(thread){
        res.json(thread.params);
    })
})

app.listen(EXPRESS_APP, function () {
  console.log('Example app listening on port ' + EXPRESS_APP);
});


/* Instagram API */
var PrivateAPI = require('instagram-private-api');
var server = PrivateAPI.ProxyServer;

server.run({
    port: PROXY_APP,
    socketPort: PROXY_SOCKET,
    host: "127.0.0.1",
    databaseDir: './databases',
    cookiesDir: './cookies'
});

var ClientProxy = PrivateAPI.ProxyClient.V1;
var server = new ClientProxy.Server('127.0.0.1', PROXY_APP, PROXY_SOCKET);
var session = new ClientProxy.Session(server);

var promise = session.create('n0tabot', 'dhillon');
var session;

promise.then(function(sessionInstance) {
  session = sessionInstance;
  console.log("Session created!");

  //ClientProxy.Thread.subscribeAll(session, function(threads) {
  //   use socket.io (http://socket.io/docs/) in order to get notified when something in inbox
  //})

  //ClientProxy.Thread.subscribe(session, thread.id, function(thread) {
  //   use socket.io if you want to build realtime chat app, this will be called every
  //   time when someone respond to the thread, this wil poll only one thread, so it is much faster
  //   then subscribeAll which will poll for whole inbox
  //})
})

function getThreads() {
  if(!session) return Promise.resolve([]);
  return ClientProxy.Thread.all(session, 100);   
}

function getThread(id) {
  if(!session) return Promise.resolve({});
  return ClientProxy.Thread.show(session, id, 300); 
} 

from instagram-private-api.

dhillon2325 avatar dhillon2325 commented on June 5, 2024

Okay, thank you I will try this. And I am slowly learning NodeJS 👍

from instagram-private-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.