forked from dilame/instagram-private-api
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupload-photo-from-web.example.ts
25 lines (21 loc) · 1 KB
/
upload-photo-from-web.example.ts
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
/* tslint:disable:no-console */
import 'dotenv/config';
import { IgApiClient } from '../src';
import { get } from 'request-promise'; // request is already declared as a 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 as a Buffer
const imageBuffer = await get({
url: 'https://picsum.photos/800/800', // random picture with 800x800 size
encoding: null, // this is required, only this way a Buffer is returned
});
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"
})();