Created
July 23, 2014 18:03
-
-
Save freekrai/69d40148e1aa9609cdc3 to your computer and use it in GitHub Desktop.
Grab latest images via instagram
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
<?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; | |
} | |
function instagram($user = '1256702813'){ | |
// https://api.instagram.com/v1/users/1256702813/media/recent/?access_token=1604938.5657c5c.403459e283f84109b55e7114776af98e | |
$token = "1604938.5657c5c.403459e283f84109b55e7114776af98e"; | |
$result = fetchData("https://api.instagram.com/v1/users/{$user}/media/recent/?access_token={$token}"); | |
$result = json_decode($result); | |
$cnt = 0; | |
foreach ($result->data as $post) { | |
?> | |
<div class="col-xs-4 col-sm-3 col-md-1 col-lg-1"> | |
<a href="<?php echo $post->link?>" title="<?php echo htmlentities($post->caption->text)?>"> | |
<img src="<?php echo $post->images->low_resolution->url?>" alt="" class="img-circle margin-bottom-10"> | |
</a> | |
</div> | |
<?php | |
$cnt++; | |
if( $cnt == 8 ) break; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment