dilame / instagram-private-api

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

Use with Meteor #161

Closed nicholaai closed 7 years ago

nicholaai commented 7 years ago

First off, thanks for the repo!

I've been able to use it via a barebones node app but I was wondering if anyone could give advise on integrating this repo with Meteor. I did a fresh install of meteor + react and installed the package via npm. Created an event handler and within my main.js file in my server folder added the following (yes i've properly set username / pw / and added a cookies folder with the username json):

`import { Meteor } from 'meteor/meteor';

var Client = require('instagram-private-api').V1;

Meteor.startup(() => { // code to run on server at startup });

Meteor.methods({ testIg() { var device = new Client.Device('username'); var storage = new Client.CookieFileStorage(__dirname + './cookies/username.json'); console.log(this is device: ${device}); console.log(this is storage: ${storage}) // And go for login Client.Session.create(device, storage, 'someuser', 'somepassword') .then(function(session) { console.log(this is session ${session}); // Now you have a session, we can follow / unfollow, anything... // And we want to follow Instagram official profile return [session, Client.Account.searchForUser(session, 'instagram')] }) .spread(function(session, account) { console.log(this is account ${account}); return Client.Relationship.create(session, account.id); }) .then(function(relationship) { console.log(relationship.params) // {followedBy: ... , following: ... } // Yey, you just followed @instagram }); } }) `

I also tried using:

import { InstagramPrivateAPI } from 'instagram-private-api';

With that, I get the following error:

W20170312-21:48:52.391(-7)? (STDERR) /Users/Nicholas/.meteor/packages/meteor-tool/.1.4.3_1.1bk3ru3++os.osx.x86_64+web.browser+web.cordova/mt-os.osx.x86_64/dev_bundle/server-lib/node_modules/fibers/future.js:280 W20170312-21:48:52.391(-7)? (STDERR) throw(ex); W20170312-21:48:52.391(-7)? (STDERR) ^ W20170312-21:48:52.392(-7)? (STDERR) W20170312-21:48:52.392(-7)? (STDERR) Error: Cannot find module './client/v1' W20170312-21:48:52.392(-7)? (STDERR) at require (packages/modules-runtime.js:123:19) W20170312-21:48:52.393(-7)? (STDERR) at meteorInstall.node_modules.instagram-private-api.index.js (packages/modules.js:354:26) W20170312-21:48:52.393(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:197:9) W20170312-21:48:52.393(-7)? (STDERR) at require (packages/modules-runtime.js:120:16) W20170312-21:48:52.393(-7)? (STDERR) at meteorInstall.server.main.js (server/main.js:3:14) W20170312-21:48:52.393(-7)? (STDERR) at fileEvaluate (packages/modules-runtime.js:197:9) W20170312-21:48:52.394(-7)? (STDERR) at require (packages/modules-runtime.js:120:16) W20170312-21:48:52.394(-7)? (STDERR) at /Users/Nicholas/Development/instaFame/.meteor/local/build/programs/server/app/app.js:44:1 W20170312-21:48:52.394(-7)? (STDERR) at /Users/Nicholas/Development/instaFame/.meteor/local/build/programs/server/boot.js:303:34 W20170312-21:48:52.394(-7)? (STDERR) at Array.forEach (native) => Exited with code: 1 => Your application is crashing. Waiting for file change.

Any idea how to get this working? Would I have to write a meteor wrapper? Thanks!

indesignlatam commented 7 years ago

Hello @nicholaai,

I think you are doing just on thing wrong, your not importing it correctly. But after importing you will find another issue with the cookie. (For that i use an absolute path).

This is how I do it

import { V1 as InstagramClient } from 'instagram-private-api';

const device = new InstagramClient.Device('username');
const storage = new InstagramClient.CookieFileStorage('/Users/xxx/proyect/cookies/username.json');

// And go for login
InstagramClient.Session.create(device, storage, 'username', 'password')
.then((session) => {
    // Now you have a session, we can follow / unfollow, anything...
    // And we want to follow Instagram official profile
    return [session, InstagramClient.Account.searchForUser(session, 'instagram')];
})
.spread((session, account) => {
    return InstagramClient.Relationship.create(session, account.id);
})
.then((relationship) => {
    console.log(relationship.params);
    // {followedBy: ... , following: ... }
    // Yey, you just followed @instagram
});

Hope it helps.

Cheers.