-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (24 loc) · 859 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
require('dotenv').config()
require('instagram-private-api')
const Client = require('instagram-private-api').V1;
const device = new Client.Device(process.env.IG_USER);
const storage = new Client.CookieFileStorage(`./cookies/${process.env.IG_USER}.json`);
// And go for login
Client.Session.create(
device,
storage,
process.env.IG_USER,
process.env.IG_PASSWORD
).then(function (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) {
return Client.Relationship.create(session, account.id);
})
.then(function (relationship) {
console.log(relationship.params)
// {followedBy: ... , following: ... }
// Yey, you just followed @instagram
})