-
-
Save arturmamedov/7f5a90b85a20e06e344ebb88dc898d25 to your computer and use it in GitHub Desktop.
<?php | |
// yo can follow this guide to http://www.benrlodge.com/blog/post/how-to-generate-an-instagram-access-token# | |
#1 first you need to create a Client in Instgram Developer Dashboard | |
// https://www.instagram.com/developer/clients/manage/ | |
#2 after you need to retrive a oAuth code for after get access_token | |
// https://www.instagram.com/developer/authentication/ | |
// change the params with your one and open link in browser | |
// https://www.instagram.com/oauth/authorize/?client_id=YOUR_CLIENT_ID_GOES_HERE&redirect_uri=THAT_REDIRECT_URI_YOU_GAVE&response_type=code | |
// at this point you have a code ex: http://www.YOUR_REDIRECT_LINK.com?code=asdf4a0c15d80bc54ddea32d6f1751 | |
// we need the code "asdf4a0c15d80bc54ddea32d6f1751" | |
# for use it in pour CURL request and obtain a access_token | |
// curl native commands | |
//curl -F 'client_id=CLIENT_ID' \ | |
// -F 'client_secret=CLIENT_SECRET' \ | |
// -F 'grant_type=authorization_code' \ | |
// -F 'redirect_uri=AUTHORIZATION_REDIRECT_URI' \ | |
// -F 'code=CODE' \ | |
// | |
/// curl with PHP | |
$uri = 'https://api.instagram.com/oauth/access_token'; | |
$data = [ | |
'client_id' => '213esdaedasdasd12...YOUR_CLINT_ID', | |
'client_secret' => 'a8b4aaf06c0da310...YOUR_CLIENT_SECRET', | |
'grant_type' => 'authorization_code', | |
'redirect_uri' => 'http://www.YOUR_REDIRECT_URL.it', | |
'code' => 'asdf4a0c15d80bc54ddea32d6f1751...retrivedCODE' | |
]; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $uri); // uri | |
curl_setopt($ch, CURLOPT_POST, true); // POST | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); // POST DATA | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // RETURN RESULT true | |
curl_setopt($ch, CURLOPT_HEADER, 0); // RETURN HEADER false | |
curl_setopt($ch, CURLOPT_NOBODY, 0); // NO RETURN BODY false / we need the body to return | |
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); // VERIFY SSL HOST false | |
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); // VERIFY SSL PEER false | |
$result = json_decode(curl_exec($ch)); // execute curl | |
echo '<pre>'; // preformatted view | |
// ecit directly the result | |
exit(print_r($result)); | |
?> |
Thanks arturmamedov. It was very helpful.
Thanks for sharing this. I've dabbled in command line curl but wasn't sure how to do the equivalent in PHP so this was exceptionally helpful.
acc thank you so so much this worked perfectly
молоток! :)
I have tried But I am getting error like
stdClass Object
(
[error_type] => OAuthException
[code] => 400
[error_message] => Invalid Client ID
)
1
Please advise
Please advise
Hi @Selvasan02 maybe instagram disable something i don't know, i pass to a more automated solution that permitt instagram photos from username, hashtag or location in any combination see example on this website https://www.hotelcityrimini.com/
For get it you need to subscribe a plan here https://goo.gl/dBnGNo
https://elfsight.com/?ref=d3805a92-b32f-41e2-890c-40d0422384f5
And after you can use an Instagram API library for retrive your pics:
jQInstaPics - https://jsfiddle.net/arturmamedov/c89sdhbd/
instafeed.js - https://jsfiddle.net/arturmamedov/om3mnm09/