InstagramJS
Javascript wrapper around Instagram API
Features
- Promise based
- No browser support (sorry, can't get excited about JSONP)
- Tested on NodeJS 6, 7, 8
Install
npm i instagramjs
Usage
All requests are made using an access token. See Authentication for a step-by-step guide on how to obtain a token.
const Instagram = require('instagramjs')
const access = new Instagram('access_token')
Note: to quickly get a token for testing purposes, check out our InstAuth tool.
Global config
Below are defaults:
const access = new Instagram('access_token', {
baseURL: 'https://api.instagram.com/v1',
fullResponse: false,
timeout: 0
})
Scenarios
User
access.user('self').get()
.then(console.log)
access.user('id').get()
.then(console.log)
access.user('id').media().get()
.then(console.log)
access.user('self').media('liked').get({count: 20})
.then(console.log)
access.user().search({q: 'foo'})
.then(console.log)
User Relationship
access.user('self').follows().get()
.then(console.log)
access.user('self').followedBy().get()
.then(console.log)
access.user('self').requestedBy().get()
.then(console.log)
access.user('id').relationship().get()
.then(console.log)
access.user('id').relationship().post({action: 'unfollow'})
.then(console.log)
Media
access.media('id').get()
.then(console.log)
access.media().shortcode('abc').get()
.then(console.log)
access.media().search({distance: 1000, lat: 10, lng: 20})
.then(console.log)
access.media('id').comment().get()
.then(console.log)
access.media('id').comment('cid').delete().then(() => {
console.log('deleted')
})
Media Likes
access.media('id').like().get()
.then(console.log)
access.media('id').like().post().then(() => {
console.log('liked')
})
access.media('id').like().delete().then(() => {
console.log('deleted')
})
Tags
access.tag('name').get()
.then(console.log)
access.tag('name').media().get()
.then(console.log)
access.tag().search({q: 'foo'})
.then(console.log)
Locations
access.location('id').get()
.then(console.log)
access.location('id').media().get()
.then(console.log)
access.location().search({distance: 100, lat: 5, lng: 10})
.then(console.log)
Request Options
As you might've noticed in the exaples, it's possible to specify
query params in the request options, e. g.:
access.user('self').media('liked').get({count: 20})
Additionaly, a full response option could be enabled for a single request:
access.user('self').get(true).then(console.log)
{
status: 200,
headers: { ... },
data: { ... }
}
If you need to specify request timeout:
access.user('self').get(100)
And, finally, combination of above:
access.user('self').get({foo: 'bar'}, true, 100)
Custom Request
If some of the endpoints are not available via Resource interface, it's always possible
to build a custom request:
access.request({
url: '/my/url',
method: 'get',
params: {
foo: 'bar'
},
fullResponse: false,
timeout: 0
}).then(console.log)