Skip to content

Instantly share code, notes, and snippets.

@justindocanto
Last active June 12, 2016 06:01
Show Gist options
  • Save justindocanto/ce30af2ce12d0eba007d67c995e16dd9 to your computer and use it in GitHub Desktop.
Save justindocanto/ce30af2ce12d0eba007d67c995e16dd9 to your computer and use it in GitHub Desktop.
Get last 12 Instagram photos in PHP using /username/media/ json feed
<div class="row">
<?php
function fetchData($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 20);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$result = fetchData("https://www.instagram.com/[USERNAME]/media/");
$result = json_decode($result);
$i = 0;
foreach ($result->items as $item) {
if($i < 12) {
?>
<div class="col-md-2 col-xs-3">
<a href="<?php echo $item->images->standard_resolution->url; ?>">
<img src="<?php echo $item->images->thumbnail->url; ?>" title="<?php echo $item->caption->text; ?>">
</a>
</div>
<?php
$i++;
}
}
?>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment