A Parse cloud module for the Instagram API.
To use this module you need to register as developer on Instagram and obtain a client_id here: http://instagram.com/developer/. The site contains the API documentation and other important information, such as usage terms, API throttling, and how to authenticate users.
Simply copy the module (e.g. instagram-v1-1.0.js
) into your Cloud Code Directory by placing it in the cloud
directory.
To use the module in your Cloud Code functions, start by requiring it and initializing it with your credentials:
var ig = require('cloud/instagram-v1-1.0.js');
ig.initialize('YOUR_CLIENT_ID');
Some methods require an access token to be passed as parameter. To generate the access token you can refer to the documentation here: http://instagram.com/developer/authentication/. Once the user has authenticated your app and you have obtained the token, you can either pass it as a parameter to each call, or you can set it as a global variable.
ig.setAccessToken('ACCESS_TOKEN');
The Instagram Cloud Module uses (and requires use of) JavaScript Promises.
// This example is inside of a Cloud Function:
ig.searchUser({
q: 'jack',
count: '3'
}).then(function(httpResponse) {
response.success(httpResponse.data);
},
function(error) {
response.error(error);
});
This is the list of methods available in the module and their correspondent Instagram API endpoint. You can find examples of cloud code calling these functions in the main.js file.
Cloud module function | Instagram endpoint | Notes |
searchUser(params, options) | /users/search | |
searchTag(params, options) | /tags/search | |
searchLocation(params, options) | /locations/search | |
getUser(userID, params, options) | /users/USER_ID | |
getTag(tagName, params, options) | /tags/TAG_NAME | |
getLocation(locationID, params, options) | /locations/LOCATION_ID | |
getPopularMedia(params, options) | /media/popular | |
getRecentMediaByUser(userID, params, options) | /users/USER_ID/media/recent | Requires an access_token |
getRecentMediaByTag(tagName, params, options) | /tags/TAG_NAME/media/recent/ | |
getRecentMediaByLocation(locationID, params, options) | /locations/LOCATION_ID/media/recent | |
getSelfFeed(params, options) | /users/self/feed | Requires an access_token |
getSelfLikedMedia(params, options) | /users/self/media/liked | Requires an access_token |
getNextPage(nextUrl, options) | Use this method for pagination. |