Last active
June 12, 2016 06:01
-
-
Save justindocanto/ce30af2ce12d0eba007d67c995e16dd9 to your computer and use it in GitHub Desktop.
Get last 12 Instagram photos in PHP using /username/media/ json feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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