-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
34 lines (31 loc) · 1.07 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
const axios = require('axios')
/*
* Retrieves recent photos from instagram
* Parameters:
* access_token - Instagram access token. See instagram api instructions on how to get one.
* username - Instagram username. Defaults to `self` when not indicated
*/
function scrape(access_token, username='self') {
const base_url = `https://api.instagram.com/v1/users/${username}/media/recent/?access_token=${access_token}`
return axios.get(base_url)
.then(function (response) {
let instagram = []
response.data.data.map( (pageItem) => {
// Post ID, Image Caption, Images
const instagramItem = {
last_id: pageItem.id,
caption: pageItem.caption,
thumbnail: pageItem.images.thumbnail.url,
low_resolution: pageItem.images.low_resolution.url,
standard_resolution: pageItem.images.standard_resolution.url
}
// Add instagram item to array
instagram.push(instagramItem)
})
return instagram
})
.catch( error => {
console.log(error);
});
}
module.exports = {scrape}