-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
52 lines (36 loc) · 1.23 KB
/
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
const fs = require('fs');
const axios = require('axios');
let getImages = async() => {
let accessToken = fs.readFileSync('instaToken.json');
var config = {
method: 'get',
url: 'https://graph.instagram.com/me/media?fields=media_type,media_url&access_token=' + accessToken,
};
let getImagesRequest = await axios(config);
const actiondata = getImagesRequest.data.data;
let imagesData = JSON.stringify(actiondata);
fs.writeFileSync('images.json', imagesData);
// console.log(actiondata);
console.log("=========");
console.log("Images scraped and written to file!");
console.log("=========");
}
let refreshToken = async() => {
let accessToken = fs.readFileSync('instaToken.json');
var config = {
method: 'get',
url: 'https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=' + accessToken,
};
let refreshTokenRequest = await axios(config);
const newToken = refreshTokenRequest.data.access_token;
fs.writeFileSync('instaToken.json', newToken);
console.log("=========");
console.log("New Token:")
console.log(newToken);
console.log("=========");
}
console.log('scraper online!');
getImages();
refreshToken();
setInterval(getImages, 900000);
setInterval(refreshToken, 864000000);