{"id":20767030,"url":"https://github.com/binded/ig-node","last_synced_at":"2025-03-11T18:51:32.038Z","repository":{"id":97906326,"uuid":"95186854","full_name":"binded/ig-node","owner":"binded","description":null,"archived":false,"fork":false,"pushed_at":"2017-06-23T05:42:59.000Z","size":170,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-18T06:28:14.945Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/binded.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-06-23T05:41:06.000Z","updated_at":"2017-06-23T05:42:41.000Z","dependencies_parsed_at":null,"dependency_job_id":"82b96f0d-99d3-4bd1-9be4-cbbb01e0cff1","html_url":"https://github.com/binded/ig-node","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fig-node","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fig-node/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fig-node/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/binded%2Fig-node/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/binded","download_url":"https://codeload.github.com/binded/ig-node/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243094628,"owners_count":20235531,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-17T11:27:22.049Z","updated_at":"2025-03-11T18:51:32.002Z","avatar_url":"https://github.com/binded.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"instagram-node\n==============\n\nNodeJS driver for the Instagram API.\nIn production at http://totems.co aggregating more than 200 data points per seconds\n\n## Installation\n\n`npm install instagram-node`\n\n## How it works\n\n* First of all, you need to authentify. You can use `client_id/client_secret` from the app you are building, or an `access_token` from\na user that use your app.\n* **Some features need an access_token to work**\n\n```javascript\nvar ig = require('instagram-node').instagram();\n\n// Every call to `ig.use()` overrides the `client_id/client_secret`\n// or `access_token` previously entered if they exist.\nig.use({ access_token: 'YOUR_ACCESS_TOKEN' });\nig.use({ client_id: 'YOUR_CLIENT_ID',\n         client_secret: 'YOUR_CLIENT_SECRET' });\n```\n\n* If you activated \"Signed Requests\", you need to sign requests that need the\nwrite access (relationship, likes, comments, ...) with:\n```javascript\napp.post('/like/:media_id', function(req, res, next) {\n  var ig = require('instagram-node').instagram({});\n  ig.use({ access_token: 'YOUR_ACCESS_TOKEN' });\n\n  ig.add_like(req.param('media_id'), {\n    sign_request: {\n      client_secret: 'YOUR_CLIENT_SECRET',\n      // Then you can specify the request:\n      client_req: req\n      // or the IP on your own:\n      ip: 'XXX.XXX.XXX.XXX'\n    }\n  }, function(err) {\n    // handle err here\n    return res.send('OK');\n  });\n});\n```\n\n### Server-Side Authentication using OAuth and the Instagram API\n\nInstagram uses the standard oauth authentication flow in order to allow apps to act on\na user's behalf. Therefore, the API provides two convenience methods to help\nyou authenticate your users. The first, ```get_authorization_url```, can be used\nto redirect an unauthenticated user to the instagram login screen based on a\n```redirect_uri``` string and an optional ```options``` object containing\nan optional ```scope``` array and an optional ```state``` string. The\nsecond method, ```authorize_user```, can be used to retrieve and set an access token\nfor a user, allowing your app to act fully on his/her behalf. This method takes\nthree parameters: a ```response_code``` which is sent as a GET parameter once a\nuser has authorized your app and instagram has redirected them back to your\nauthorization redirect URI, a ```redirect_uri``` which is the same one \nsupplied to ```get_authorization_url```, and a callback that takes\ntwo parameters ```err``` and ```result```. ```err``` will be populated if and\nonly if the request to authenticate the user has failed for some reason.\nOtherwise, it will be ```null``` and ```response``` will be populated with a\nJSON object representing Instagram's confirmation reponse that the user is\nindeed authorized. See [instagram's authentication\ndocumentation](http://instagram.com/developer/authentication/) for more information.\n\nBelow is an example of how one might authenticate a user within an ExpressJS app.\n```javascript\nvar http = require('http');\nvar express = require('express');\nvar api = require('instagram-node').instagram();\nvar app = express();\n\napp.configure(function() {\n  // The usual...\n});\n\napi.use({\n  client_id: YOUR_CLIENT_ID,\n  client_secret: YOUR_CLIENT_SECRET\n});\n\nvar redirect_uri = 'http://yoursite.com/handleauth';\n\nexports.authorize_user = function(req, res) {\n  res.redirect(api.get_authorization_url(redirect_uri, { scope: ['likes'], state: 'a state' }));\n};\n\nexports.handleauth = function(req, res) {\n  api.authorize_user(req.query.code, redirect_uri, function(err, result) {\n    if (err) {\n      console.log(err.body);\n      res.send(\"Didn't work\");\n    } else {\n      console.log('Yay! Access token is ' + result.access_token);\n      res.send('You made it!!');\n    }\n  });\n};\n\n// This is where you would initially send users to authorize\napp.get('/authorize_user', exports.authorize_user);\n// This is your redirect URI\napp.get('/handleauth', exports.handleauth);\n\nhttp.createServer(app).listen(app.get('port'), function(){\n  console.log(\"Express server listening on port \" + app.get('port'));\n});\n\n```\n\n###Using the API\n\nOnce you've setup the API and/or authenticated, here is the full list of what you can do:\n\n```javascript\n/********************************/\n/*            USERS             */\n/********************************/\nig.user('user_id', function(err, result, remaining, limit) {});\n\n/* OPTIONS: { [count], [min_id], [max_id] }; */\nig.user_self_feed([options,] function(err, medias, pagination, remaining, limit) {});\n\n/* OPTIONS: { [count], [min_timestamp], [max_timestamp], [min_id], [max_id] }; */\nig.user_media_recent('user_id', [options,] function(err, medias, pagination, remaining, limit) {});\n\n/* OPTIONS: { [count], [min_timestamp], [max_timestamp], [min_id], [max_id] }; */\nig.user_self_media_recent([options,] function(err, medias, pagination, remaining, limit) {});\n\n/* OPTIONS: { [count], [max_like_id] }; */\nig.user_self_liked([options,] function(err, medias, pagination, remaining, limit) {});\n\n/* OPTIONS: { [count] }; */\nig.user_search('username', [options,] function(err, users, remaining, limit) {});\n\n/********************************/\n/*         RELATIONSHIP         */\n/********************************/\n/* OPTIONS: { [count], [cursor] }; */\nig.user_follows('user_id', function(err, users, pagination, remaining, limit) {});\n\n/* OPTIONS: { [count], [cursor] }; */\nig.user_followers('user_id', function(err, users, pagination, remaining, limit) {});\n\nig.user_self_requested_by(function(err, users, remaining, limit) {});\n\nig.user_relationship('user_id', function(err, result, remaining, limit) {});\n\nig.set_user_relationship('user_id', 'follow', function(err, result, remaining, limit) {});\n\n/********************************/\n/*           MEDIAS             */\n/********************************/\nig.media('media_id', function(err, media, remaining, limit) {});\n\n/* OPTIONS: { [min_timestamp], [max_timestamp], [distance] }; */\nig.media_search(48.4335645654, 2.345645645, [options,] function(err, medias, remaining, limit) {});\n\nig.media_popular(function(err, medias, remaining, limit) {});\n\n/********************************/\n/*           COMMENTS           */\n/********************************/\nig.comments('media_id', function(err, result, remaining, limit) {});\n\nig.add_comment('media_id', 'your comment', function(err, result, remaining, limit) {});\n\nig.del_comment('media_id', 'comment_id', function(err, remaining, limit) {});\n\n/********************************/\n/*            LIKES             */\n/********************************/\nig.likes('media_id', function(err, result, remaining, limit) {});\n\nig.add_like('media_id', function(err, remaining, limit) {});\n\nig.del_like('media_id', function(err, remaining, limit) {});\n\n/********************************/\n/*             TAGS             */\n/********************************/\nig.tag('tag', function(err, result, remaining, limit) {});\n\n/* OPTIONS: { [min_tag_id], [max_tag_id] }; */\nig.tag_media_recent('tag', [options,] function(err, medias, pagination, remaining, limit) {});\n\nig.tag_search('query', function(err, result, remaining, limit) {});\n\n/********************************/\n/*           LOCATIONS          */\n/********************************/\nig.location('location_id', function(err, result, remaining, limit) {});\n\n/* OPTIONS: { [min_id], [max_id], [min_timestamp], [max_timestamp] }; */\nig.location_media_recent('location_id', [options,] function(err, result, pagination, remaining, limit) {});\n\n/* SPECS: { lat, lng, [foursquare_v2_id], [foursquare_id] }; */\n/* OPTIONS: { [distance] }; */\nig.location_search({ lat: 48.565464564, lng: 2.34656589 }, [options,] function(err, result, remaining, limit) {});\n\n/********************************/\n/*          GEOGRAPHIES         */\n/********************************/\n/* OPTIONS: { [min_id], [count] } */\nig.geography_media_recent(geography_id, [options,] function(err, result, pagination, remaining, limit) {});\n\n/********************************/\n/*         SUBSCRIPTIONS        */\n/********************************/\nig.subscriptions(function(err, result, remaining, limit){});\n\nig.del_subscription({id:1}, function(err,subscriptions,limit){})\n\n/* OPTIONS: { [verify_token] } */\nig.add_tag_subscription('funny', 'http://MYHOST/tag/funny', [options,] function(err, result, remaining, limit){});\n\n/* OPTIONS: { [verify_token] } */\nig.add_geography_subscription(48.565464564, 2.34656589, 100, 'http://MYHOST/geography', [options,] function(err, result, remaining, limit){});\n\n/* OPTIONS: { [verify_token] } */\nig.add_user_subscription('http://MYHOST/user', [options,] function(err, result, remaining, limit){});\n\n/* OPTIONS: { [verify_token] } */\nig.add_location_subscription(1257285, 'http://MYHOST/location/1257285', [options,] function(err, result, remaining, limit){});\n```\n\n## Subscriptions\n\nSubscriptions are callbacks from Instagram to your app when new things happen. They should be web-accessable, and return `req.query['hub.challenge']` on GET. Read more [here](http://instagram.com/developer/realtime/). After you subscribe, Instagram will calllback your web URL whenever a new post, user action, etc happens.\n\nYou can get your subscriptions with this:\n\n```javascript\nig.subscriptions(function(err, subscriptions, remaining, limit){\n  console.log(subscriptions);\n});\n```\n\nYou can delete all your subscriptions with this:\n\n```javascript\nig.del_subscription({ all: true }, function(err, subscriptions, remaining, limit){});\n```\n\nor just one with this:\n\n```javascript\nig.del_subscription({ id: 1 }, function(err, subscriptions, remaining, limit){});\n```\n\n\n\n## Errors\n\nWhen errors occur, you receive an error object with default properties, but we also add some other things:\n\n    // Available when the error comes from Instagram API\n    err.code;                // code from Instagram\n    err.error_type;          // error type from Instagram\n    err.error_message;       // error message from Instagram\n\n    // If the error occurs while requesting the API\n    err.status_code;         // the response status code\n    err.body;                // the received body\n\nand\n\n    err.retry(); // Lets you retry in the same conditions that before\n\n## Pagination\n\nWhen you use functions like `user_media_recent` or `tag_media_recent`, you will get a `pagination` object in your callback. This object\nis basically the same that Instagram would give you but there will be a `next()` function that let you retrieve next results without caring about anything.\n\n```javascript\nvar ig = require('instagram-node').instagram();\n\nvar hdl = function(err, result, pagination, remaining, limit) {\n  // Your implementation here\n  if(pagination.next) {\n    pagination.next(hdl); // Will get second page results\n  }\n};\n\nig.tag_media_recent('test', hdl);\n```\n\n## Tests\n\nPut the following in your environment:\n\n    export INSTAGRAM_ACCESS_TOKEN=YOUACCESSTOKEN\n\nThen just use\n\n    make test\n\n## More infos\n\n* You can find more informations on the [Instagram developer](http://instagram.com/developer) website.\n* If you have any questions or remark, feel free to contact us at `hello@totems.co`\n\n## License\n\nDistributed under the MIT License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fig-node","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbinded%2Fig-node","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbinded%2Fig-node/lists"}