forked from dilame/instagram-private-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupload-photo-from-web.example.ts
More file actions
28 lines (23 loc) · 1.11 KB
/
Copy pathupload-photo-from-web.example.ts
File metadata and controls
28 lines (23 loc) · 1.11 KB
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
27
28
/* tslint:disable:no-console */
import 'dotenv/config';
import { IgApiClient } from '../src';
import { get } from 'request-promise'; // request is already declared as an dependency of the library
(async () => {
const ig = new IgApiClient();
ig.state.generateDevice(process.env.IG_USERNAME);
ig.state.proxyUrl = process.env.IG_PROXY;
const auth = await ig.account.login(process.env.IG_USERNAME, process.env.IG_PASSWORD);
console.log(JSON.stringify(auth));
// getting random square image from internet
const imageRequest = await get({
url: 'https://picsum.photos/800/800', // random picture with 800x800 size
encoding: null, // this is required, we could convert body to buffer only with null encoding
});
// converting image body to buffer
const imageBuffer = Buffer.from(imageRequest.body, 'binary');
const publishResult = await ig.publish.photo({
file: imageBuffer, // image buffer, you also can specify image from your disk using fs
caption: 'Really nice photo from the internet! 💖', // nice caption (optional)
});
console.log(publishResult); // publishResult.status should be "ok"
})();