{"id":15989305,"url":"https://github.com/peter279k/instagram-auth-example","last_synced_at":"2025-08-08T02:42:56.402Z","repository":{"id":79147086,"uuid":"271573609","full_name":"peter279k/instagram-auth-example","owner":"peter279k","description":"This is the Instagram authentication example scripts","archived":false,"fork":false,"pushed_at":"2020-06-12T14:37:33.000Z","size":9,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-17T21:05:02.229Z","etag":null,"topics":["instagram","instagram-api","instagram-basic-display-api"],"latest_commit_sha":null,"homepage":null,"language":"Shell","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/peter279k.png","metadata":{"files":{"readme":"README.md","changelog":null,"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":"2020-06-11T14:52:46.000Z","updated_at":"2022-04-06T17:30:43.000Z","dependencies_parsed_at":"2023-06-27T02:06:34.997Z","dependency_job_id":null,"html_url":"https://github.com/peter279k/instagram-auth-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/peter279k/instagram-auth-example","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter279k%2Finstagram-auth-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter279k%2Finstagram-auth-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter279k%2Finstagram-auth-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter279k%2Finstagram-auth-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peter279k","download_url":"https://codeload.github.com/peter279k/instagram-auth-example/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peter279k%2Finstagram-auth-example/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269355716,"owners_count":24403497,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["instagram","instagram-api","instagram-basic-display-api"],"created_at":"2024-10-08T04:41:35.984Z","updated_at":"2025-08-08T02:42:56.359Z","avatar_url":"https://github.com/peter279k.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# instagram-auth-example\nThis is the Instagram authentication example scripts\n\n# Instagram Authentication Steps\n\n## Authenticate the test user\n- Before starting following steps, please refer this [Gist link](https://gist.github.com/peter279k/1c3ed14473b8055057d0213d759e92ed).\n- We assume that you've registered Facebook App ID and enable the completed Instagram Basic Display ID features.\n- Please refer and run [auth_test_user.sh](auth_test_user.sh).\n\n![alt_img](https://imgur.com/dlPVfqo.png)\n\n![alt_img](https://i.imgur.com/p41j2B4.png)\n\n```Bash\n#!/bin/bash\n\napp_id=\"instagram_app_id\"\nredirect_uri=\"oauth_instagram_redirect_url\"\n\nfirefox \"https://api.instagram.com/oauth/authorize?client_id=\"${app_id}\"\u0026redirect_uri=\"${redirect_uri}\"\u0026scope=user_profile,user_media\u0026response_type=code\"\n\n# It will get authorization codes\n\n# https://oauth_instagram_redirect_url.website/auth/?code={your_authorization_code}#_\n\n# Copy above url with code param value without \"#_\" character\n\n```\n\n## Exchange code for the token\n\n- Please refer and run [exchange_code_for_token.sh](exchange_code_for_token.sh).\n\n```Bash\n#!/bin/bash\n\ncode=\"authorization_code\"\napp_id=\"instagram_app_id\"\napp_secret=\"instagram_app_secret\"\n\n# oauth_instagram_redirect_url will be same as previous redirect_uri during auth_test_user.sh running!\nredirect_uri=\"oauth_instagram_redirect_url\"\n\ncurl -X POST \\\n  https://api.instagram.com/oauth/access_token \\\n  -F client_id=${app_id} \\\n  -F client_secret=${app_secret} \\\n  -F grant_type=authorization_code \\\n  -F redirect_uri=${redirect_uri} \\\n  -F code=${code}\n\n```\n\n- The sample response will be as follows:\n\n```JSON\n{\"access_token\": \"short_lived_access_token\", \"user_id\": \"user_id\"}\n```\n\n##  Query the User Node\n\n- Query the user node via above access token\n\n```Bash\n#!/bin/bash\n\naccess_token=\"above_access_token\"\nuser_id=\"user_id\"\n\ncurl -X GET \\\n  \"https://graph.instagram.com/${user_id}?fields=id,username\u0026access_token=${access_token}\"\n\necho \"\"\n\ncurl -X GET \\\n  \"https://graph.instagram.com/me?fields=id,username\u0026access_token=${access_token}\"\n\n```\n\n- The sample response is as follows:\n\n```JSON\n{\"id\":\"instagram_user_id\",\"username\":\"instagram_user_name\"}\n```\n\n## Get a Long-Lived Token\n\n- There're two ways to get a Long-Lived Token:\n  - Using Token Generator\n\n![alt_img](https://imgur.com/d2vumwZ.png)\n\n  - Using the following Bash script. Refer [get_long_lived_token.sh](get_long_lived_token.sh)\n\n```Bash\n#!/bin/bash\n\napp_secret=\"instagram_app_secret\"\nshort_lived_access_token=\"short_lived_access_token\"\n\n# If letting cURL present response headers, remove -i option\n\ncurl -i -X GET \"https://graph.instagram.com/access_token?grant_type=ig_exchange_token\u0026client_secret=${app_secret}\u0026access_token=${short_lived_access_token}\"\n\n```\n\n- The sample response is as follows:\n\n```JSON\n{\"access_token\":\"long_lived_access_token\",\"token_type\":\"bearer\",\"expires_in\":5184000}\n```\n\n## Refresh a Long-Lived Token\n\n- Using following Bash script and refer [refresh_long_lived_token.sh](refresh_long_lived_token.sh)\n\n```Bash\n#!/bin/bash\n\nexpired_long_lived_access_token=\"expired_long_lived_access_token\"\n\ncurl -i -X GET \"https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token\u0026access_token=${expired_long_lived_access_token}\"\n```\n\n- The sample response is as follows:\n\n```JSON\n{\"access_token\":\"long_lived_access_token\",\"token_type\":\"bearer\",\"expires_in\":5183449}\n```\n\n## Get User Profiles and User Media\n\n### Get a User’s Media\n\n- Using following Bash script and refer [get_user_media.sh](get_user_media.sh)\n\n```Bash\n#!/bin/bash\n\naccess_token=\"access_token\"\n\ncurl -X GET \\\n    \"https://graph.instagram.com/me/media?fields=id,caption\u0026access_token=${access_token}\"\n```\n\n- Default limit data is `25` and it can set `limit` param on request URL to set limit data number. (max limit data number is `80`)\n- The sample response is as follows:\n\n```JSON\n{\n  \"data\": [\n    {\n      \"id\": \"18137050651011961\"\n    },\n    {\n      \"id\": \"17871491986635679\"\n    },\n    {\n      \"id\": \"17946792001336274\",\n      \"caption\": \"#紅葉國小\"\n    },\n    {\n      \"id\": \"17890427956485428\"\n    },\n    {\n      \"id\": \"17895048049463316\"\n    },\n    {\n      \"id\": \"17856103459887624\",\n      \"caption\": \"#鹿野\"\n    },\n    {\n      \"id\": \"17901981256453805\"\n    },\n    {\n      \"id\": \"17885941990521309\",\n      \"caption\": \"#鯉魚山\"\n    },\n    {\n      \"id\": \"17882981587530952\"\n    },\n    {\n      \"id\": \"17844567542071793\"\n    },\n    {\n      \"id\": \"18122891203079538\"\n    },\n    {\n      \"id\": \"18082696999170900\"\n    },\n    {\n      \"id\": \"17859966562790929\"\n    },\n    {\n      \"id\": \"17842574663067799\",\n      \"caption\": \"#墨洋拉麵\"\n    },\n    {\n      \"id\": \"17854845658827440\"\n    },\n    {\n      \"id\": \"18092942026193855\"\n    },\n    {\n      \"id\": \"17854438720851186\",\n      \"caption\": \"#老地方觀機平台\"\n    },\n    {\n      \"id\": \"18132065770021334\",\n      \"caption\": \"#豚骨咖哩飯\"\n    },\n    {\n      \"id\": \"18128504467030119\",\n      \"caption\": \"#starbucks\\n#meetwithfriends\"\n    },\n    {\n      \"id\": \"17993536255286565\",\n      \"caption\": \"#蚵爹之家\"\n    },\n    {\n      \"id\": \"18101814856103420\",\n      \"caption\": \"#沙溪堡\\n#沙溪坑道\"\n    },\n    {\n      \"id\": \"17858814256703410\"\n    },\n    {\n      \"id\": \"17883320632488803\",\n      \"caption\": \"#芋頭冰\"\n    },\n    {\n      \"id\": \"17844005662909075\"\n    },\n    {\n      \"id\": \"17853219847770998\",\n      \"caption\": \"#擎天廳\"\n    }\n  ],\n  \"paging\": {\n    \"cursors\": {\n      \"before\": \"{before_token_param}\",\n      \"after\": \"{after_token_param}\"\n    },\n    \"next\": \"https://graph.instagram.com/v1.0/{user_id}/media?access_token={access_token}\u0026fields=id%2Ccaption\u0026limit=25\u0026after={after_token_param}\"\n  }\n}\n```\n\n### Get Media Data\n\n- Default limit data is `25` and it can set `limit` param on request URL to set limit data number. (max limit data number is `80`)\n- Using following Bash script or refer [get_media_data.sh](get_media_data.sh).\n\n```Bash\n#!/bin/bash\n\nuser_id=\"me/media/\"\naccess_token=\"access_token\"\n\ncurl -X GET \\\n    \"https://graph.instagram.com/${user_id}?fields=id,media_type,media_url,username,timestamp\u0026access_token=${access_token}\"\n\n```\n\n- The sample response is as follows:\n\n```JSON\n{\n  \"data\": [\n    {\n      \"id\": \"17861912218925283\",\n      \"media_type\": \"CAROUSEL_ALBUM\",\n      \"media_url\": \"https://scontent.cdninstagram.com/v/t51.2885-15/103047977_1158542857846565_1367304746422318254_n.jpg?_nc_cat=111\u0026_nc_sid=8ae9d6\u0026_nc_ohc=OosReTDky7kAX-ULx3g\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=ba2a1113bc5f32979601d669c4686966\u0026oe=5F06B686\",\n      \"username\": \"peter279k\",\n      \"timestamp\": \"2020-06-11T17:36:09+0000\"\n    },\n    {\n      \"id\": \"17871491986635679\",\n      \"media_type\": \"IMAGE\",\n      \"media_url\": \"https://scontent.cdninstagram.com/v/t51.2885-15/91465033_259754968372982_409755531119174105_n.jpg?_nc_cat=109\u0026_nc_sid=8ae9d6\u0026_nc_ohc=OzXwCakgkGQAX-q_2CT\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=1b791abbe3ba0d33133154ea29d0f311\u0026oe=5F08B40C\",\n      \"username\": \"peter279k\",\n      \"timestamp\": \"2020-04-02T07:23:44+0000\"\n    },\n    {\n      \"id\": \"17946792001336274\",\n      \"media_type\": \"IMAGE\",\n      \"media_url\": \"https://scontent.cdninstagram.com/v/t51.2885-15/91612257_2971857936197919_702226242484782862_n.jpg?_nc_cat=104\u0026_nc_sid=8ae9d6\u0026_nc_ohc=fHZge7GictoAX-t2MDA\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=7def588e6aa2d9639a8978ed2aa8ca54\u0026oe=5F0764CB\",\n      \"username\": \"peter279k\",\n      \"timestamp\": \"2020-04-02T05:57:40+0000\"\n    },\n    ......\n  ],\n  \"paging\": {\n    \"cursors\": {\n      \"before\": \"{before_token_param}\",\n      \"after\": \"{after_token_param}\"\n    },\n    \"next\": \"https://graph.instagram.com/v1.0/17841403128568296/media?access_token={access_token}\u0026fields=id%2Cmedia_type%2Cmedia_url%2Cusername%2Ctimestamp\u0026limit=25\u0026after={after_token_param}\"\n  }\n}\n```\n\n## Get Album Contents\n\n- Perform the following steps to get a collection of image and video Media on an album Media.\n- Default limit data is `25` and it can set `limit` param on request URL to set limit data number. (max limit data number is `80`)\n- Using following Bash script or refer [get_album_contents.sh](get_album_contents.sh).\n\n```Bash\n#!/bin/bash\n\nmedia_id=\"media_id\"\naccess_token=\"access_token\"\n\ncurl -X GET \\\n    \"https://graph.instagram.com/${media_id}/children?fields=id,media_type,media_url,username,timestamp\u0026access_token=${access_token}\"\n\n```\n\n- The sample response is as follows:\n\n```JSON\n{\n  \"data\": [\n    {\n      \"id\": \"18121908406106194\",\n      \"media_type\": \"IMAGE\",\n      \"media_url\": \"https://scontent.cdninstagram.com/v/t51.2885-15/103047977_1158542857846565_1367304746422318254_n.jpg?_nc_cat=111\u0026_nc_sid=8ae9d6\u0026_nc_ohc=OosReTDky7kAX-ULx3g\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=ba2a1113bc5f32979601d669c4686966\u0026oe=5F06B686\",\n      \"username\": \"peter279k\",\n      \"timestamp\": \"2020-06-11T17:36:09+0000\"\n    },\n    {\n      \"id\": \"17926691989391970\",\n      \"media_type\": \"IMAGE\",\n      \"media_url\": \"https://scontent.cdninstagram.com/v/t51.2885-15/102912714_285788732472357_2321417626557789464_n.jpg?_nc_cat=107\u0026_nc_sid=8ae9d6\u0026_nc_ohc=RhmG6Wel9_gAX_vHOBx\u0026_nc_ht=scontent.cdninstagram.com\u0026oh=8372fdb10bc80724ca4fcbaa4a4efa62\u0026oe=5F08CD26\",\n      \"username\": \"peter279k\",\n      \"timestamp\": \"2020-06-11T17:36:09+0000\"\n    },\n    ......\n  ]\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter279k%2Finstagram-auth-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeter279k%2Finstagram-auth-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeter279k%2Finstagram-auth-example/lists"}