In this video we learn how to connect to the Instagram API. We get an access token, connect to the user/self endpoint, and display the user data in the browser.
Step 1: Setup and App on Instagram
Head over to https://www.instagram.com/developer/ and click on the “Manage Clients” tab in the header. Create an app and make note of the Client ID, Client Secret, and Redirect URI. When the user gets to your website, you will give them a link to click on that sends them to Instagram. You will pass along your Client ID and Redirect URI when the user clicks on this link. If those two things do not match, the user will fail to authenticate with your app.
Step 2: index.php Get an Access Token
This file will contain code we need in order to get an access token. When the user is redirected back from Instagram to the Redirect URI in your app, Instagram will tag on a “code” GET variable to the url. This $_GET[‘code’] variable is what we will use to generate an access token through Instagram.
This is the curl call we will use to hit Instagram’s access_token endpoint, with all of our app credentials and the $_GET[‘code’] variable we have received from Instagram. If all credentials are correct, we will get back an access token.
$params = array( // post parmas 'client_id' => IG_CLIENT_ID, 'client_secret' => IG_CLIENT_SECRET, 'grant_type' => 'authorization_code', 'redirect_uri' => IG_REDIRECT_URI, 'code' => $_GET['code'] ); // call IG access_token endpoint with params to get a valid access token $ch = curl_init( 'https://api.instagram.com/oauth/access_token' ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_CUSTOMREQUEST, 'POST' ); curl_setopt( $ch, CURLOPT_POSTFIELDS, $params ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $response_raw = curl_exec( $ch ); $response = json_decode( $response_raw, true ); curl_close( $ch ); // display our repsonse from IG echo '<pre>'; print_r( $response ); echo '</pre>';
The access token will be displayed in the response in the browser if all credentials check out.
If there is no “code” in the URL, the user is not being redirected from Instagram. In this case the need to see a link that will direct them to Instagram allowing them to authorize with our app. The link below will send the user to Instagram. We pass along our Client ID and Redirect URI so Instagram knows the user is trying to authenticate with our app.
<!-- We need to go to IG, authorize user and redirect back to this page for a code --> <h1>Instagram</h1> <a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo IG_CLIENT_ID; ?>&redirect_uri=<?php echo IG_REDIRECT_URI; ?>&response_type=code"> GET CODE </a>
Step 3: user_info.php Display User Info from Instagram
This file will use our access token from step 1. We pass along that access token to Instagram’s “users/self” endpoint. If the access token is valid, the info for our user will be returned. We will be able to get profile pic, username, posts, followers, following, and more. Here is the curl call we make to the “users/self” endpoint in order to retrieve a users info.
// hit the users/self endpoint with our valid access token to get info on our user $ch = curl_init( 'https://api.instagram.com/v1/users/self/?access_token=' . IG_ACCESS_TOKEN ); curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true ); curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, FALSE ); $response_raw = curl_exec( $ch ); $response = json_decode( $response_raw, true ); curl_close( $ch ); echo '<pre>'; print_r( $response ); echo '</pre>';
If all is well, we will get a response back formatted just like Instagram’s documentation said we would here https://www.instagram.com/developer/endpoints/users/.
Now, lets display our user info to the browser with HTML. In the HTML below we simply access data from the response we got back from Instagram. Just like it said in the documentation, we display the users profile image, username, posts, followers, and following.
<!-- display users info via html --> <img src="<?php echo $response['data']['profile_picture']; ?>" /> <br /> <b>User Name: <?php echo $response['data']['username']; ?></b> <br /> <b>Posts: <?php echo $response['data']['counts']['media']; ?></b> <br /> <b>Followers: <?php echo $response['data']['counts']['followed_by']; ?></b> <br /> <b>Following: <?php echo $response['data']['counts']['follows']; ?></b> <br />
Links
The full code example can be found in the GitHub link above. The video tutorial for this can also be found in the YouTube link above. That is going to do it for this post! Leave any comments/questions/concerns below and thanks for stopping by the blog!
apartments in jacksonville ar apartments in moore ok xander apartments
I do consider all of the ideas you’ve presented for your post. They’re very convincing and can definitely work. Still, the posts are too quick for starters. Could you please lengthen them a bit from subsequent time? Thank you for the post.
There’s certainly a great deal to find out about this issue.I like all the points you’ve made.Visit my blog post; diet ulitmate
Hello my friend! I wish to say that this post is amazing, great written and come with almost all important infos. I¡¦d like to see more posts like this .
Hi, I do believe this is a great blog. I stumbledupon it 😉 I may return once again since i have bookmarked it. Money and freedom is the best way to change, may you be rich and continue to help other people.
When it comes to gaming, used for almost anything you’d canada clenbuterol
You completed a number of good points there. I did a search on the issue and found most folks will agree with your blog.
Very good information. Lucky me I ran across your blog by chance (stumbleupon).I’ve book marked it for later!
apartment renovation rentberry scam ico 30m$ raised ocean view apartments
Hey are using WordPress for your blog platform?I’m new to the blog world but I’m trying to get started and create my own.Do you need any coding knowledge to make your own blog?Any help would be really appreciated!
Thanks for sharing, this is a fantastic post. Much obliged.
Thanks-a-mundo for the article.Really thank you! Really Cool.
Really informative blog.Much thanks again. Really Great.
Thanks again for the blog post.Really thank you!
Thanks for the article post.Thanks Again. Really Cool.
Appreciate you sharing, great article.Really thank you! Really Cool.
I am continually invstigating online for posts that can aid me. Thx!
Thanks so much for the blog article. Fantastic.
wow, awesome article post.Much thanks again. Keep writing.
A round of applause for your blog.Much thanks again. Will read on…
Hello! Do you know if they make any plugins to safeguard against hackers?I’m kinda paranoid about losing everything I’ve worked hard on. Anysuggestions?
Aw, this was an extremely good post. Finding the time and actual effort to make a superb articleÖ but what can I sayÖ I procrastinate a whole lot and never seem to get nearly anything done.
This is a topic that’s near to my heart… Best wishes! Exactly where are your contact details though?
Earn points with each bet on our all new Sportsbetting kiosks!
A round of applause for your blog article. Really Great.
I loved your article. Keep writing.
Enjoyed every bit of your post.Thanks Again. Really Cool.
พนันบอลอย่างไรให้ได้เงิน แทงบอลชนะยังไงไม่ถูกโกง UFABET จ่ายจริงจ่ายไม่ยั้งระบบเข้าใจง่าย แค่เพียงคลิกสมัครก็ทำเงินได้อย่างง่ายๆกับคาสิโนออนไลน์ สบายสุดๆชีวิตชิวๆชีวิตคลูๆทำเงิน สร้างกำไรสบายๆจึงควรที่ UFABET
Amazing things here. I am very satisfied tosee your post. Thank you so much and I’m taking a look ahead to touchyou. Will you please drop me a mail?
I do not even know the way I stopped up right here, however I thought this submit used to be great.I do not realize who you are but definitely you are going to a famous blogger ifyou happen to are not already. Cheers!
There is visibly a bundle to know about this. I believe you made various good points in features also.
doxy 200: doxycycline tetracycline – doxycycline mono
Hi, this weekend is fastidious in support of me,for the reason that this point in time i am reading this fantastic educational paragraph here at myhome.
This is a truly respected post. Thanks as a service to posting this
Thanks for finally talking about > Granada: Monuments and Moments – Simplicity’s Sake
Fantastic blog article.Really thank you! Really Great.
I am not sure where you’re getting your info, but good topic.I needs to spend some time learning more or understanding more.Thanks for wonderful info I was looking for this information for mymission.
Greetings! Very useful advice in this particular post!It is the little changes that make the most important changes.Thanks a lot for sharing!
Looking forward to reading more. Great blog.Much thanks again. Will read on…
It¡¦s actually a nice and helpful piece of information. I am happy that you just shared this helpful information with us. Please keep us up to date like this. Thanks for sharing.
Im grateful for the blog.Really thank you! Awesome.
Hello there! This post couldn’t be written any better! Reading this post reminds me of my previous room mate! He always kept chatting about this. I will forward this article to him. Fairly certain he will have a good read. Thanks for sharing!
It’s really a nice and helpful piece of info. I’m happy thatyou just shared this helpful info with us. Please keep usinformed like this. Thank you for sharing. natalielise plenty of fish
Thanks for any other magnificent article. Where else could anyone get that kind of info in such an ideal way of writing? I have a presentation next week, and I am on the look for such information.
1 over the counter ed pill – vacuum treatment for erectile dysfunction over the counter ed pills at cvs
Whoa tons of awesome advice! canadian online pharmacies
A big thank you for your blog.Really looking forward to read more. Awesome.
Awesome post.Thanks Again. Fantastic.
Muchos Gracias for your post.Really looking forward to read more. Awesome.
I appreciate you sharing this article post.Really thank you! Great.
Appreciate you sharing, great article post.Thanks Again. Cool.
Great blog.Really thank you! Really Great.
Im grateful for the blog post.Really looking forward to read more. Keep writing.
ivermectin oral solution ivermectin in canada for humans
you will understand that both and it was far to be that easy, we
There is definately a lot to know about this issue. I really like all of the points you have made.
Thanks for the post. Awesome.
Hey, thanks for the blog post.Really looking forward to read more. Great.
Thank you ever so for you blog article.Thanks Again. Much obliged.
Very good blog.Really thank you! Awesome.
I really enjoy the post.Really looking forward to read more. Fantastic.
Thanks again for the article post.Thanks Again. Awesome.
Say, you got a nice blog post. Fantastic.
Thank you ever so for you blog. Really Cool.
Major thankies for the blog post.Really thank you! Fantastic.
Major thankies for the blog article.Much thanks again. Really Great.Loading…
I cannot thank you enough for the blog post.Really looking forward to read more. Great.
fantastic issues altogether, you simply won a emblem new reader. What could you recommend about your post that you just made some days in the past? Any positive?
Fantastic blog.Much thanks again. Much obliged.
I really enjoy the blog article.Really looking forward to read more. Really Cool.
Major thanks for the blog. Great.
Great, thanks for sharing this article.Thanks Again.
Looking forward to reading more. Great blog article.Much thanks again. Cool.
Thanks so much for the post.Really thank you! Really Cool.
510283 318357You may locate effective specific development of any L . a . Weight loss program and each and every youre very essential. To begin with level is an natural misplacing during the too significantly weight. shed belly fat 152586
เมื่อออนไลน์ปัง ทำอย่างไรถึงจะระงับใจตัวเองไม่ให้ซื้อของออนไลน์ หาวิธีระงับใจของตัวเองไม่ให้โอน ไม่ให้ซื้อ ไม่ให้จ่าย 1 หักดิบบอกตัวเองว่าจะเลิกซื้อ 2 กดไว้ก่อนแล้วค่อยซื้อ 3 ลบแอป ฯ Mobile Banking ทำให้ ซื้อของออนไลน์
Wow, great post.Much thanks again. Cool.
Aw, this was an extremely good post. Finding the time and actual effort to make a very good article… but what can I say… I hesitate a whole lot and never seem to get anything done.
When someone writes an article he/she retains the thought of a user in his/her mind that how a user can be aware of it. Therefore that’s why this paragraph is great. Thanks!
Cyucvs – persuasive essay writing Dirlrv ghsbpg
Say, you got a nice post.Really thank you! Keep writing.
With thanks, Good stuff! mexican pharmacy online
Hey, thanks for the post. Much obliged.
Appreciate you sharing, great article. Fantastic.
Patrick Mahomes has stunned fans time and time once again with hisno-look throws, but even he had to credit Ryan Fitzpatrick soon after his game-winner.
Im obliged for the blog post. Really Great.
Heya just wanted to give you a brief heads up and let you know a few of the images aren’t loading correctly.I’m not sure why but I think its a linking issue.I’ve tried it in two different internet browsers and both show the same outcome.
I cannot thank you enough for the article post.Much thanks again. Awesome.
Looking forward to reading more. Great article post.Much thanks again. Really Great.
I really enjoy the article post.Really looking forward to read more. Will read on…
Thanks again for the article.Thanks Again. Really Cool.
Awesome article post. Awesome.
This is one awesome article.Thanks Again. Will read on…
Im obliged for the article.Really looking forward to read more. Much obliged.
Say, you got a nice blog.Really looking forward to read more.
I appreciate you sharing this article.Thanks Again. Awesome.
It’s nearly impossible to find well-informed people for this topic, however, you seem like you know what you’re talking about! Thanks
Say, you got a nice post.Much thanks again. Awesome.
I always spent my half an hour to read this blog’s posts daily along with a cup of coffee.
Thank you ever so for you blog article.Thanks Again. Will read on…
Hey, thanks for the blog article.Really thank you! Fantastic.
Great, thanks for sharing this blog post.Really thank you! Great.
Stream SHOWTIME sequence, motion pictures, documentaries,sports and much more all on your favorite gadgets.
I loved your blog post.Really looking forward to read more. Really Cool.
Hello my friend! I wish to say that this article is amazing, great written and come with almost all vital infos. I would like to see extra posts like this .
Very neat article. Keep writing.
I really enjoy the post.Much thanks again. Will read on…
Aw, this was a really good post. Spending some time and actual effort to make a great article… but what can I say… I hesitate a lot and never seem to get anything done.
Awesome article post.Much thanks again. Keep writing.
hi!,I like your writing so much! share we be in contact extra about your article on AOL? I require an expert in this area to unravel my problem. May be that is you! Taking a look ahead to look you.
plaquenil arthritis quineprox 900 can plaquenil cause weight loss how long to wait inbetween plaquenil dosing
พนันบอลอย่างไรให้ได้เงิน พนันบอลชนะยังไงผิดคดโกง UFABET จ่ายจริงจ่ายไม่ยั้งระบบเข้าใจง่าย แค่เพียงคลิกสมัครก็ทำเงินได้อย่างไม่ยากเย็นกับคาสิโนออนไลน์ สบายสุดๆชีวิตชิวๆชีวิตคลูๆทำเงิน สร้างกำไรสบายๆจึงควรที่ UFABET
wow, awesome blog article.Thanks Again. Really Great.
Just wanna say that this is very useful , Thanks for taking your time to write this.
Great blog article.Much thanks again. Really Cool.
Sweetie House chuyên Kinh doanh bán sỉ và bán lẻ các loại hạt dinh dưỡng và sản phẩm thực phẩm từ Mỹ Úc. hatdinhduongsweetie@gmail.com address: 320/14 Trần Bình Trọng Phường 4 Quận 5
Hey there! Do you know if they make any plugins to help with SEO? I’m trying to get my blog to rank for some targeted keywords but I’m not seeing very good results. If you know of any please share. Kudos!
I think this is a real great post.Really thank you! Great.
Hello, all is going nicely here and ofcourse every one is sharing data,that’s truly excellent, keep up writing.
fantastic issues altogether, you simply received a new reader.What may you recommend in regards to your submit that you madea few days in the past? Any sure?
Looking forward to reading more. Great post.Much thanks again. Will read on…
Thank you for every other fantastic post. Where else may just anyone get that type of info in such a perfect manner of writing? I have a presentation subsequent week, and I’m at the search for such info.
Thanks for sharing, this is a fantastic article post. Will read on…
Thanks again for the blog post.Thanks Again. Much obliged.
Hey, thanks for the article post.Really looking forward to read more. Really Great.
This is one awesome blog article.Thanks Again. Cool.
Fantastic blog article.Really thank you! Awesome.
wow, awesome article post. Want more.
Thanks-a-mundo for the article.Really looking forward to read more. Will read on…
Thanks so much for the article post. Will read on…
side effects of quetiapine fumarate can quetiapine be crushed
come guadagnare bitcoin gratisbitcoin for live 5cd11e7
Major thankies for the blog post.Really thank you! Really Great.
Lo Shake a Via di Monte Testaccio 35 a Roma, è a location perfetta dove organizzare una festa di compleanno ma anche eventi di altro genere come ad esempio un’evento aziendale, una festa di laurea
No matter if some one searches for his Essential Nutrition Muscle thing, therefore he/sheneeds to be available that in detail, thus that thing is maintained over here.
Thanks so much for the article.Really looking forward to read more. Will read on…
Liên Kết Coi Thẳng Bóng Đá Futsal Việt Nam Vs Lebanon Vòng Loại World Cupwest ham đấu với liverpoolNếu cứ nghịch như cơ hội vừa đè bẹp Everton tới 3-1 trên sân khách hàng
I do believe all the ideas you’ve introduced to your post. They are very convincing and can definitely work. Still, the posts are too brief for newbies. May you please prolong them a little from subsequent time? Thanks for the post.
ed problems treatment erectile dysfunction pills best ed treatment
hello!,I love your writing so so much! share we keep up a correspondence more approximately your article on AOL? I require an expert in this area to resolve my problem. Maybe that is you! Looking forward to look you.
Hi! I’m at work surfing around your blog from my new apple iphone!Just wanted to say I love reading through your blog and look forward to allyour posts! Keep up the fantastic work!
I am extremely impressed with your writing skills aswell as with the layout on your blog. Is this a paid theme or didyou modify it yourself? Either way keep up the nice quality writing, it’s rare to see a great blog like this one today.
🥇สมัครฟรี🥇ไม่ต้องโยกเงิน🥇ฝาก-ถอนระบบออโต้ ขั้นต่ำ 1 uาท🥇ที่สำคัญ ไม่ลดการชนะ ทุกเกมส์🥇ปลอดภัย ดูแลดี บริการ 24 ชม.🥇ชวนเพื่อน รับโบนัสทันที20🥇ขอให้เราได้เป็นส่วนหนึ่งในการดูแลรายได้ของคุณ🥇สมัครเลย >
Thanks designed for sharing such a good idea, paragraph is fastidious, thats whyi have read it fully
Thanks again for the blog post. Great.
I value the article post.Really looking forward to read more. Really Great.
chicken lice treatment ivermectin alternative to ivermectin
A big thank you for your blog.Much thanks again. Really Great.
Thanks a lot for the article.Really thank you! Keep writing.
It’s an amazing post designed for all the web visitors; they will obtain benefit from it I am
sure.
Fantastic article.Really thank you! Awesome.
plaquenil weight gain hydroxychloroquine ingredients
чтоб приобрести документы в россии , диплом купить о среднем прибегайте к достоверным исполнителям!
ed help canadian pharmacy online – best online pharmacy india