Instagram Basic Display API: Obtaining an Access Token

In this post we learn how to obtain and access token from the Instagram Basic Display API with a code passed to us from Instagram once the user has authorized our application. The access token we get is short lived meaning it will only be valid for an hour or so. In the next blog post we will learn how to exchange this short lived access token, for a long lived access token which can be used for up to 60 days.

Required to continue: Facebook app with Instagram product added

Step 1: Generate the Authorization URL

This URL will take the user to Instagram and present them with a pop up. The pop up will ask the user to Authorize our app so our app can read the users Instagram information.

app pop up

Authorization URL Structure

https://api.instagram.com/oauth/authorize?app_id={app-id}&redirect_uri={redirect-uri}&scope=user_profile,user_media&response_type=code

  • {app-id}: Instagram App ID. In the developer app dashboard got to “Instagram > Basic Display”
  • {redirect-uri}: This must match a URI that has been entered into the apps “Valid OAuth Redirect URIs” in the apps dashboard.

 
app creds

Once you have the Authorization URL, place it inside of an <a> tag for the user to click on.

<!-- Link to take user to Instagram for authorization with our app -->
<a href="https://api.instagram.com/oauth/authorize?app_id={app-id}&redirect_uri={redirect-uri}&scope=user_profile,user_media&response_type=code">
    Authorize W/Instagram
</a>

Step 2: Obtaining the Access Token

When the user Authorizes our app, Instagram sends them to the {redirect-uri} we passed along in the authorization URL and appends on a code. On our website, we will check for this code in the URL. If code exists in the URL, use it to get an access token. If no code variable exists in the URL, display the “Authorize W/Instagram” link from step 1 above. The URL will look like this.

Instagram Redirect URI with code: {redirect-uri}?code={ig-code}
 

Access Token API Endpoint

Endpoint
https://api.instagram.com/oauth/access_token

Type
POST

Params

  • app_id: Instagram App ID. In the developer app dashboard go to “Instagram > Basic Display” and copy the “Instagram App ID”.
  • app_secret: Instagram App Secret. In the developer app dashboard go to “Instagram > Basic Display” and copy the “Instagram App Secret”.
  • redirect_uri: This must match one of the URIs that has been entered into the apps “Valid OAuth Redirect URIs” in the apps dashboard.
  • grant_type: authorization_code
  • code: {ig-code}

 

PHP CURL call to the Access Token API Endpoint

// base endpoint
$endpoint = 'https://api.instagram.com/oauth/access_token';

// params the endpoint requires
$params = array(
	'app_id' => 'INSTAGRAM_APP_ID', // our instagram app id
	'app_secret' => 'INSTAGRAM_APP_SECRET', // our instagram app secret
	'grant_type' => 'authorization_code',
	'redirect_uri' => 'INSTAGRAM_APP_REDIRECT_URI', // our redirect uri
	'code' => $_GET['code'] // code instagram sent us in the URL
);			

// open curl call
$ch = curl_init();

// set type to post and pass the fields along 
curl_setopt( $ch, CURLOPT_POSTFIELDS, http_build_query( $params ) );
curl_setopt( $ch, CURLOPT_POST, 1 );

// set curl url
curl_setopt( $ch, CURLOPT_URL, $endpoint );

// set other curl options
curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false ); 
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

// get response, close curl, make php array
$response = curl_exec( $ch );

// close cur
curl_close( $ch );

// make nice php array :D
$responseArray = json_decode( $response, true );

// print out the response array that contains the access token
echo '<pre>';
print_r( $responseArray );

This CURL call hits our Instagram endpoint with the required parameters and receives a response from Instagram with an access token. If any of the parameters are incorrect, an error message will be returned. The access token here is a short lived access token meaning it is not valid for very long. In the next post, this short lived access token will be exchanged for a long lived access token.

Links
Code on GitHub

YouTube Video

That is going to do it for this post! Leave any comments/questions/concerns below and thanks for stopping by the blog!

168 comments

  1. 벼룩시장 신문그대로보기 (구인구직, 부동산) 벼룩시장 신문그대로보기 바로가기 그리고 지역별 벼룩시장 종이신문그대로보기 방법 (구인구직, 부동산) 알아볼게요. 교차로신문 같이 벼룩시장은 지역별 일자리, 구인구직, 부동산 등 다양한 정보를 제공해요. 교차로신문그대로보기 바로가기는 아래에서 확인하고, 오늘은 벼룩시장 신문그대로보기 바로가기 그리고 사용법 섹스카지노사이트

  2. Hello! This is my 1st commnent here so I juwt wanted to give a quick
    shout out annd tell yoou I ttuly enjoy redading throujgh your blog posts.
    Can you suggest anyy othedr blogs/websites/forums thaqt deal
    wit the same subjects? Applreciate it!

  3. Its like you read my mind! You appear to understand a lot approximately this, such as you wrote the e book in it or something. I feel that you could do with a few to power the message house a little bit, however other than that, that is great blog. A great read. I will certainly be back.

  4. A person essentially assist to make seriously posts I might state. That is the very first time I frequented your web page and to this point? I surprised with the research you made to make this particular post extraordinary. Great task!

  5. Thank you a bunch for sharing this with all people you actually understand what you’re talking approximately! Bookmarked. Please additionally visit my website =). We can have a hyperlink exchange contract between us!

  6. Its such as you learn my mind! You seem to know so much approximately this, like you wrote the e-book in it or something. I feel that you could do with a few p.c. to pressure the message home a little bit, however instead of that, that is great blog. An excellent read. I’ll certainly be back.

  7. Do you have a spzm issue onn this site; I also am a blogger, annd
    I was wondering yohr situation; wwe have ceated soe
    nice proceduures and wwe are looking tto wap techniques ith other folks,
    please shoot mee an e-mail iif interested.

  8. Thanks for another magnificent post. Where else could anyone get that kind of information in such an ideal way of writing? I’ve a presentation next week, and I am on the look for such information.

  9. Excellent post. I was checkiing continuously tis blpog aand I’m impressed!

    Extremely heppful information specifically tthe las part :
    ) I care for suchh infoo much. I wass loooking for thiss certain informatioon forr a
    verfy long time. Thank yoou andd best of luck.

  10. A few things i have observed in terms of personal computer memory is that often there are specs such as SDRAM, DDR or anything else, that must fit the requirements of the motherboard. If the pc’s motherboard is pretty current and there are no computer OS issues, updating the memory literally will take under one hour. It’s one of the easiest laptop upgrade methods one can visualize. Thanks for spreading your ideas.

  11. Almost all of the things you say happens to be supprisingly precise and it makes me ponder why I had not looked at this with this light previously. This article really did switch the light on for me personally as far as this subject matter goes. However there is one particular issue I am not really too comfortable with and while I attempt to reconcile that with the actual main theme of your point, let me see just what all the rest of the visitors have to say.Very well done.

  12. I have been absent for a while, but now I remember why I used to love this site. Thanks , I’ll try and check back more often. How frequently you update your website?

  13. I want to show thanks to the writer just for rescuing me from this particular challenge. Because of looking throughout the online world and finding tricks which were not helpful, I figured my life was well over. Living minus the solutions to the issues you’ve resolved by means of the article content is a crucial case, as well as the kind that would have negatively damaged my career if I hadn’t encountered your blog post. Your primary talents and kindness in dealing with all the details was excellent. I’m not sure what I would have done if I had not come across such a step like this. I’m able to at this moment look ahead to my future. Thanks for your time so much for this impressive and result oriented guide. I won’t be reluctant to refer your web site to anyone who would like assistance about this topic.

  14. Wow, awesome blog layout! How long have you been blogging for? you made blogging look easy. The overall look of your website is magnificent, as well as the content!

  15. https://itgunza.com

    https//pornmaster.fun/hd/吉安哪裏有小姐全套包夜服務薇信▷182-888-04吉安哪裏有小姐全套包夜服務吉安哪裏有小姐大保健按摩特殊服務▷吉安哪裏有小姐學生妹過夜上門按摩服務-nip

  16. Thanks for the ideas you are revealing on this site. Another thing I’d really like to say is the fact getting hold of copies of your credit score in order to inspect accuracy of any detail would be the first action you have to conduct in credit repair. You are looking to clean up your credit profile from dangerous details mistakes that mess up your credit score.

  17. I wanted to post you this very small remark to be able to thank you so much as before relating to the great pointers you’ve shared here. It was simply remarkably generous with you to provide freely what most of us could possibly have made available for an e-book to get some cash on their own, primarily considering that you could have tried it in case you desired. These guidelines also served like a fantastic way to understand that other people online have a similar keenness the same as mine to figure out way more with respect to this condition. I am sure there are millions of more pleasant instances up front for people who discover your site.

  18. The following time I read a blog, I hope that it doesnt disappoint me as much as this one. I mean, I know it was my option to read, but I actually thought youd have one thing interesting to say. All I hear is a bunch of whining about one thing that you can fix for those who werent too busy looking for attention.

  19. Aw, this was a really nice post. In idea I would like to put in writing like this moreover – taking time and precise effort to make a very good article… but what can I say… I procrastinate alot and certainly not seem to get one thing done.

  20. I found your blog site on google and test a couple of of your early posts. Continue to maintain up the excellent operate. I just further up your RSS feed to my MSN Information Reader. Looking for ahead to reading more from you later on!…

  21. After study a number of of the weblog posts in your web site now, and I actually like your manner of blogging. I bookmarked it to my bookmark website listing and can be checking again soon. Pls try my website online as properly and let me know what you think.

  22. My husband and i felt so delighted when Michael managed to carry out his analysis while using the ideas he came across when using the web site. It’s not at all simplistic to just continually be giving freely concepts which some people could have been trying to sell. Therefore we keep in mind we have you to give thanks to for this. The type of explanations you’ve made, the easy web site menu, the friendships you can help instill – it’s got most exceptional, and it is letting our son in addition to the family believe that the concept is interesting, which is tremendously vital. Thanks for all the pieces!

  23. I抎 must test with you here. Which is not something I normally do! I take pleasure in reading a put up that will make people think. Additionally, thanks for allowing me to comment!

  24. One thing I would like to say is the fact that before purchasing more computer memory, look into the machine in to which it is installed. Should the machine will be running Windows XP, for instance, the actual memory threshold is 3.25GB. Using in excess of this would easily constitute any waste. Make sure that one’s mother board can handle an upgrade volume, as well. Good blog post.

  25. With havin so much content and articles do you ever run into any issues of plagorism or copyright infringement? My site has a lot of completely unique content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the web without my authorization. Do you know any ways to help prevent content from being ripped off? I’d genuinely appreciate it.

  26. Hmm is anyone else encountering problems with the pictures on this blog loading?I’m trying to determine if its a problem on my end or ifit’s the blog. Any responses would be greatly appreciated.

  27. I do not even understand how I stopped up right here, however I assumed this submit was once great. I do not recognise who you might be however definitely you are going to a well-known blogger if you are not already. Cheers!

  28. Wow! This can be one particular of the most useful blogs We have ever arrive across on this subject. Basically Magnificent. I’m also an expert in this topic so I can understand your effort.

  29. I loved as much as you’ll receive carried out right here. The sketch is tasteful, your authored subject matter stylish. nonetheless, you command get bought an impatience over that you wish be delivering the following. unwell unquestionably come more formerly again since exactly the same nearly very often inside case you shield this increase.

  30. I needed to thank you for this very good read!! I absolutely loved every little bit of it. I have got you bookmarked to check out new things you post…

  31. Hi would you mind sharing which blog platform you’re working with? I’m planning to start my own blog in the near future but I’m having a tough time making a decision between BlogEngine/Wordpress/B2evolution and Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely unique. P.S Sorry for being off-topic but I had to ask!

  32. I’m really enjoying the design and layout of your blog.It’s a very easy on the eyes which makes it much more enjoyable for me to come here and visit more often. Did you hireout a designer to create your theme? Exceptional work!

  33. I think that is among the so much significant information for me. And i’m satisfied reading your article. However wanna observation on few basic issues, The website style is perfect, the articles is really nice : D. Good task, cheers

  34. I don抰 even know how I ended up right here, however I believed this publish used to be great. I don’t know who you might be but certainly you are going to a famous blogger should you are not already 😉 Cheers!

  35. Asking questions are truly pleasant thing if you are notunderstanding something totally, but this piece of writingprovides fastidious understanding yet.

  36. No matter if some one searches for his necessary thing, thus he/shewishes to be available that in detail, thus that thing is maintained over here.

  37. One more thing. It’s my opinion that there are many travel insurance web pages of respected companies that let you enter your journey details to get you the estimates. You can also purchase your international holiday insurance policy on-line by using your credit card. All that you should do is usually to enter your own travel particulars and you can begin to see the plans side-by-side. Merely find the package that suits your financial allowance and needs after which use your credit card to buy the item. Travel insurance online is a good way to do investigation for a respected company regarding international travel insurance. Thanks for giving your ideas.

  38. It’s difficult to find well-informed people about this topic, but you sound like you know what you’re talking about! Thanks

  39. Those are yours alright! . We at least need to get these people stealing images to start blogging! They probably just did a image search and grabbed them. They look good though!

  40. Excellent post. I was checking continuously this blog and I’m impressed!Very helpful info specially the last part 🙂 I care for such information much.I was looking for this particular info for a long time.Thank you and best of luck.

  41. F*ckin’ amazing issues here. I am very satisfied to peer your article. Thank you so much and i’m having a look ahead to contact you. Will you kindly drop me a mail?

  42. I love your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you? Plz respond as I’m looking to create my own blog and would like to know where u got this from. thanks

  43. With everything that appears to be developing throughout this specific area, your points of view happen to be quite stimulating. However, I am sorry, because I can not subscribe to your whole idea, all be it exhilarating none the less. It seems to me that your remarks are actually not entirely rationalized and in simple fact you are generally your self not really entirely confident of the assertion. In any event I did enjoy reading through it.

  44. Whats Taking place i am new to this, I stumbled upon this I’ve discovered It absolutely helpful and it has aided me out loads. I am hoping to give a contribution & assist different users like its aided me. Great job.

  45. Wow! This can be one particular of the most helpful blogs We have ever arrive across on this subject. Actually Magnificent. I am also an expert in this topic therefore I can understand your hard work.

  46. I was recommended this website by my cousin. I’m not certain whether this submit is written via him as no one else recognise such precise about my trouble. You’re wonderful! Thank you!

  47. This site can be a stroll-through for all of the information you wished about this and didn’t know who to ask. Glimpse right here, and also you’ll definitely uncover it.

  48. Oh my goodness! a tremendous article dude. Thank you Nevertheless I’m experiencing challenge with ur rss . Don’t know why Unable to subscribe to it. Is there anyone getting equivalent rss downside? Anybody who knows kindly respond. Thnkx

  49. Hi there! I’m at work browsing your blog from my new iphone! Just wanted to say I love reading through your blog and look forward to all your posts! Carry on the great work!

  50. Hiya, I’m really glad I’ve found this information. Nowadays bloggers publish just about gossips and internet and this is really frustrating. A good site with interesting content, that’s what I need. Thank you for keeping this web site, I will be visiting it. Do you do newsletters? Can not find it.

  51. Hello there, I discovered your site by means of Google while searching for a related matter, your site got here up, it seems to be great. I have bookmarked it in my google bookmarks.

  52. My partner and I absolutely love your blog and find nearly all of your post’s to be exactly what I’m looking for. can you offer guest writers to write content for you personally? I wouldn’t mind creating a post or elaborating on many of the subjects you write about here. Again, awesome web site!

  53. The best way to use our Groupon coupons is to choose the’see sale’ solution from your Lively delivers detailedandFree Coupons – Get Free Coupon Online – Store Shipping Couponfree coupons

  54. Aw, this was a really good post. Taking a few minutes and actual effort to make a superb article… but what can I say… I put things off a whole lot and never seem to get anything done.

  55. I抳e learn a few good stuff here. Definitely value bookmarking for revisiting. I surprise how much attempt you set to make one of these fantastic informative web site.

  56. Greetings! This is my first comment here so I just wanted to give a quick shout out and tell you I truly enjoy reading through your blog posts. Can you recommend any other blogs/websites/forums that deal with the same topics? Appreciate it!

  57. As the decentralized finance (DeFi) space continues to evolve in 2025, SpookySwap has established itself as one of the leading decentralized exchanges (DEXs) on the Fantom Opera blockchain. Known for fast, low-cost token swaps, yield farming, and liquidity rewards, SpookySwap is a powerful tool for traders and DeFi enthusiasts looking to maximize their returns while maintaining full control of their funds.

  58. I am not sure where you are getting your information, but
    good topic. I needs to spend some time learning more or
    understanding more. Thanks for excellent info I
    was looking for this information for my mission.

  59. Your style is unique in comparison to other folks I’ve read stuff from. Many thanks for posting when you’ve got the opportunity, Guess I’ll just bookmark this blog.

  60. Discover the future of decentralized finance with Woofi Finance, a cutting-edge platform for seamless crypto staking and yield farming. Maximize your returns with low fees and high rewards. Join the revolution in DeFi today!

Leave a Reply

Your email address will not be published. Required fields are marked *