Skip to content

Instantly share code, notes, and snippets.

@plasx
Created November 28, 2015 22:15
Show Gist options
  • Save plasx/397d7833f556f96007d1 to your computer and use it in GitHub Desktop.
Save plasx/397d7833f556f96007d1 to your computer and use it in GitHub Desktop.
php curl work
function getUserID($userName){
$url = 'https://api.instagram.com/v1/users/search?q='. $userName . '&client_id=' .clientID;
$instagramInfo = connectToInstagram($url);
$results = json_decode($instagramInfo, true);
//return $results['data'][0]['id';]
return $results['data'][0]['id'];
}
function printImages($userID){
$url = 'https://api.instagram.com/v1/users/' .$userID.'/media/recent?client_id=' . clientID . '&count=5';
$instagramInfo = connectToInstagram($url);
$results = json_decode($instagramInfo, true);
//parse through images
var_dump($results);
foreach($results['data'] as $items){
$image_url = $items['images']['low_resolution']['url'];
echo '<img src="'. $image_url . '" /><br /> ';
}
}
if($_GET['code']){
$code = $_GET['code'];
$url = "https://api.instagram.com/oauth/access_token";
$access_token_settings = array(
'client_id' => clientID,
'client_secret' => clientSecret,
'grant_type' => 'authorization_code',
'redirect_uri' => redirectURI,
'code' => $code
);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $access_token_settings);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
$results = json_decode($result, true);
echo 'This is your access token '. $results['access_token'] . ' fucking AMAZING THAT I FINALLY DID IT!!';
//echo $results['full_name'];
//echo '<img src=' . $results['user']['profile_picture'] .' />';
echo '<h1>'.$results['user']['username'].'</h1>';
$userName = $results['user']['username'];
$userID = getUserID($userName);
printImages($userID);
}else{ ?>
<!DOCTYPE html>
<html>
<head>
<title>INSTAGRAM</title>
</head>
<body>
<a href="https://api.instagram.com/oauth/authorize/?client_id=<?php echo clientID; ?>&redirect_uri=<?php echo redirectURI; ?>&response_type=code">Login</a>
</body>
</html>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment