{"id":17377387,"url":"https://github.com/pradel/node-instagram","last_synced_at":"2025-04-05T07:08:18.627Z","repository":{"id":9360114,"uuid":"61882557","full_name":"pradel/node-instagram","owner":"pradel","description":"Instagram api client for node that support promises.","archived":false,"fork":false,"pushed_at":"2022-12-08T14:26:59.000Z","size":972,"stargazers_count":190,"open_issues_count":14,"forks_count":27,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-03-29T06:09:05.697Z","etag":null,"topics":["api","authentication","instagram","nodejs","promise","stream","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pradel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-06-24T12:20:41.000Z","updated_at":"2025-03-09T02:20:44.000Z","dependencies_parsed_at":"2023-01-11T20:12:00.396Z","dependency_job_id":null,"html_url":"https://github.com/pradel/node-instagram","commit_stats":null,"previous_names":[],"tags_count":26,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pradel%2Fnode-instagram","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pradel%2Fnode-instagram/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pradel%2Fnode-instagram/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pradel%2Fnode-instagram/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pradel","download_url":"https://codeload.github.com/pradel/node-instagram/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247299833,"owners_count":20916190,"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":["api","authentication","instagram","nodejs","promise","stream","typescript"],"created_at":"2024-10-16T05:05:53.975Z","updated_at":"2025-04-05T07:08:18.599Z","avatar_url":"https://github.com/pradel.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![npm version](https://badge.fury.io/js/node-instagram.svg)](https://badge.fury.io/js/node-instagram)\n[![npm](https://img.shields.io/npm/dm/node-instagram.svg)](https://www.npmjs.com/package/node-instagram)\n[![Build Status](https://travis-ci.org/pradel/node-instagram.svg?branch=master)](https://travis-ci.org/pradel/node-instagram)\n[![Coverage Status](https://coveralls.io/repos/github/pradel/node-instagram/badge.svg?branch=master)](https://coveralls.io/github/pradel/node-instagram?branch=master)\n[![Dependency Status](https://david-dm.org/pradel/node-instagram.svg)](https://david-dm.org/pradel/node-instagram)\n[![Known Vulnerabilities](https://snyk.io/test/npm/node-instagram/badge.svg)](https://snyk.io/test/npm/node-instagram)\n\n# node-instagram\n\n\u003e ⚠️ The legacy Instagram API is deprecated and will be disabled on June 29, 2020.\n\u003e\n\u003e More information https://www.instagram.com/developer.\n\u003e\n\u003e You should use the new Instagram Graph API.\n\nInstagram api client for node that supports promises and typescript.\n\nYou can find examples in the [examples](https://github.com/pradel/node-instagram/tree/master/examples) directory.\n\n## Install\n\n`npm install --save node-instagram`\n\n`yarn add node-instagram`\n\n## Usage\n\n```javascript\nimport Instagram from \"node-instagram\";\n// or\nconst Instagram = require(\"node-instagram\").default;\n\n// Create a new instance.\nconst instagram = new Instagram({\n  clientId: \"your-client-id\",\n  clientSecret: \"your-client-secret\",\n  accessToken: \"user-access-token\"\n});\n\n// You can use callbacks or promises\ninstagram.get(\"users/self\", (err, data) =\u003e {\n  if (err) {\n    // an error occured\n    console.log(err);\n  } else {\n    console.log(data);\n  }\n});\n\n// Get information about the owner of the access_token.\nconst data = await instagram.get(\"users/self\");\nconsole.log(data);\n\n// Handle errors\ninstagram\n  .get(\"tags/paris\")\n  .then(data =\u003e {\n    console.log(data);\n  })\n  .catch(err =\u003e {\n    // An error occured\n    console.log(err);\n  });\n```\n\n## Streaming\n\nThis 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.\n\n```javascript\nconst stream = instagram.stream(\"tags/:tag-name/media/recent\");\n\nstream.on(\"messages\", messages =\u003e {\n  console.log(messages);\n});\n\n// handle stream error\nstream.on(\"error\", err =\u003e {\n  // An error occur\n  console.log(err);\n});\n```\n\n## Server side authentication\n\nTwo steps are needed in order to receive an access_token for a user.\n\n- Get an authentication url from instagram and redirect the user to it\n- Exchange the code for an access_token\n\nYou can find a working example with express [here](https://github.com/pradel/node-instagram/tree/master/examples/express-auth).\n\nTo see more info about server side authentication take a look at the [instagram documentation](https://www.instagram.com/developer/authentication/).\n\n```javascript\n// Example with express\n\n// Your redirect url where you will handle the code param\nconst redirectUri = \"http://localhost:3000/auth/instagram/callback\";\n\n// First redirect user to instagram oauth\napp.get(\"/auth/instagram\", (req, res) =\u003e {\n  res.redirect(\n    instagram.getAuthorizationUrl(\n      redirectUri,\n      {\n        // an array of scopes\n        scope: [\"basic\", \"likes\"]\n      },\n      // an optional state\n      (state: \"your state\")\n    )\n  );\n});\n\n// Handle auth code and get access_token for user\napp.get(\"/auth/instagram/callback\", async (req, res) =\u003e {\n  try {\n    // The code from the request, here req.query.code for express\n    const code = req.query.code;\n    const data = await instagram.authorizeUser(code, redirectUri);\n    // data.access_token contain the user access_token\n    res.json(data);\n  } catch (err) {\n    res.json(err);\n  }\n});\n```\n\n## Endpoints\n\nTo see all endpoint available take a look at [instagram developer documentation](https://www.instagram.com/developer/endpoints/).\n\n```javascript\n// Get information about current user\ninstagram.get(\"users/self\", (err, data) =\u003e {\n  console.log(data);\n});\n\n// Get information about a user.\ninstagram.get(\"users/:user-id\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get the most recent media published by the owner of the access_token.\ninstagram.get(\"users/self/media/recent\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get the most recent media published by a user.\ninstagram.get(\"users/:user-id/media/recent\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get the list of recent media liked by the owner of the access_token.\ninstagram.get(\"users/self/media/liked\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get a list of users matching the query.\ninstagram.get(\"users/search\", { q: \"paris\" }).then(data =\u003e {\n  console.log(data);\n});\n\n// Get information about this media.\ninstagram.get(\"media/:media-id\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get a list of users who have liked this media.\ninstagram.get(\"media/:media-id/likes\").then(data =\u003e {\n  console.log(data);\n});\n\n// Set a like on this media by the currently authenticated user.\ninstagram.post(\"media/:media-id/likes\").then(data =\u003e {\n  console.log(data);\n});\n\n// Remove a like on this media by the currently authenticated user.\ninstagram.delete(\"media/:media-id/likes\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get information about a tag object.\ninstagram.get(\"tags/:tag-name\").then(data =\u003e {\n  console.log(data);\n});\n\n// Get a list of recently tagged media.\ninstagram.get(\"tags/:tag-name/media/recent\").then(data =\u003e {\n  console.log(data);\n});\n\n// Search for tags by name.\ninstagram.get(\"tags/search\", { q: \"paris\" }).then(data =\u003e {\n  console.log(data);\n});\n```\n\nIt is also possible to send the access_token along as a parameter when you call an endpoint. For example:\n\n```javascript\n// Get information about current user\ninstagram.get(\"users/self\", { access_token: accessToken }, (err, data) =\u003e {\n  console.log(data);\n});\n\n// Search for tags by name.\ninstagram\n  .get(\"tags/search\", { access_token: accessToken, q: \"paris\" })\n  .then(data =\u003e {\n    console.log(data);\n  });\n```\n\n## Api\n\n### `const instagram = new Instagram(config)`\n\nCreate a new Instagram instance\n\n#### Arguments\n\n- `clientId` **string**\n- `accessToken` **string**\n\n### `instagram.get(endpoint, [params, callback])`\n\nMake a GET request on endpoint\n\n#### Arguments\n\n- `endpoint` **string**\n- `params` **object**\n- `callback` **function**\n\n### `instagram.post(endpoint, [params, callback])`\n\nMake a POST request on endpoint\n\n#### Arguments\n\n- `endpoint` **string**\n- `params` **object**\n- `callback` **function**\n\n### `instagram.delete(endpoint, [params, callback])`\n\nMake a DELETE request on endpoint\n\n#### Arguments\n\n- `endpoint` **string**\n- `params` **object**\n- `callback` **function**\n\n### `instagram.stream(endpoint, params)`\n\nStart a fake stream to a endpoint and return new messages found\n\n#### Arguments\n\n- `endpoint` **string**\n- `params` **object**\n- `params.interval` **number** interval to run inside **default** 10000\n- `params.runOnCreation` **boolean** run the request when creating object\n- `params.minTagId` **boolean** instagram min_tag_id to start request\n\n### `instagram.getAuthorizationUrl(redirectUri, options)`\n\nGet a valid auth url for instagram\n\n#### Arguments\n\n- `redirectUri` **string** the url to redirect the user with the code\n- `options` **object**\n- `options.scope` **array|string** the scope to request\n- `options.state` **string** optional state\n- `callback` **function**\n\n### `instagram.authorizeUser(code, redirectUri, [callback])`\n\nHandle the code returned by instagram an get a user access_token\n\n#### Arguments\n\n- `redirectUri` **string** code returned by instagram\n- `redirectUri` **string**\n- `callback` **function**\n\n## License\n\nMIT © [Léo Pradel](https://www.leopradel.com/)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpradel%2Fnode-instagram","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpradel%2Fnode-instagram","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpradel%2Fnode-instagram/lists"}