node-instagram
Instagram api client for node that support promises and typescript.
You can find examples in the examples directory.
Install
npm install --save node-instagram
yarn add node-instagram
Usage
;// orconst Instagram = default; // Create a new instance.const instagram = clientId: 'your-client-id' clientSecret: 'your-client-secret' accessToken: 'user-access-token'; // You can use callbacks or promisesinstagram; // Get information about the owner of the access_token.const data = await instagram;console; // Handle errorsinstagram ;
Streaming
This lib have a stream method. It is used to receive new post as events. Streaming can only be used on all endpoints taking MIN_TAG_ID as parameter. Inside it is running setInterval.
const stream = instagram; stream; // handle stream errorstream;
Server side authentication
Two steps are needed in order to receive an access_token for a user.
- Get an authentication url from instagram and redirect the user to it
- Exchange the code for an access_token
You can find a working example with express here.
To see more info about server side authentication take a look at the instagram documentation.
// Example with express // Your redirect url where you will handle the code paramconst redirectUri = 'http://localhost:3000/auth/instagram/callback'; // First redirect user to instagram oauthapp; // Handle auth code and get access_token for userapp;
Endpoints
To see all endpoint available take a look at instagram developer documentation.
// Get information about current userinstagram; // Get information about a user.instagram; // Get the most recent media published by the owner of the access_token.instagram; // Get the most recent media published by a user.instagram; // Get the list of recent media liked by the owner of the access_token.instagram; // Get a list of users matching the query.instagram; // Get information about this media.instagram; // Get a list of users who have liked this media.instagram; // Set a like on this media by the currently authenticated user.instagram; // Remove a like on this media by the currently authenticated user.instagram; // Get information about a tag object.instagram; // Get a list of recently tagged media.instagram; // Search for tags by name.instagram;
It is also possible to send the access_token along as a parameter when you call an endpoint. For example:
// Get information about current userinstagram; // Search for tags by name.instagram ;
Api
const instagram = new Instagram(config)
Create a new Instagram instance
Arguments
clientId
stringaccessToken
string
instagram.get(endpoint, [params, callback])
Make a GET request on endpoint
Arguments
endpoint
stringparams
objectcallback
function
instagram.post(endpoint, [params, callback])
Make a POST request on endpoint
Arguments
endpoint
stringparams
objectcallback
function
instagram.delete(endpoint, [params, callback])
Make a DELETE request on endpoint
Arguments
endpoint
stringparams
objectcallback
function
instagram.stream(endpoint, params)
Start a fake stream to a endpoint and return new messages found
Arguments
endpoint
stringparams
objectparams.interval
number interval to run inside default 10000params.runOnCreation
boolean run the request when creating objectparams.minTagId
boolean instagram min_tag_id to start request
instagram.getAuthorizationUrl(redirectUri, options)
Get a valid auth url for instagram
Arguments
redirectUri
string the url to redirect the user with the codeoptions
objectoptions.scope
array|string the scope to requestoptions.state
string optional statecallback
function
instagram.authorizeUser(code, redirectUri, [callback])
Handle the code returned by instagram an get a user access_token
Arguments
redirectUri
string code returned by instagramredirectUri
stringcallback
function
License
MIT © Léo Pradel