Created
November 19, 2013 14:40
-
-
Save nclsjstnn/7546317 to your computer and use it in GitHub Desktop.
Get a list of instagrams refereed to a tag
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){ | |
//edit here | |
$search = "mercadoconvite"; | |
$access_token = "TU_TOKEN"; | |
$count = "14"; | |
//LET IT BE | |
$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://api.instagram.com/v1/tags/".$search."/media/recent/?access_token=".$access_token."&count=".$count); | |
$cache = './instagram.json'; | |
if(file_exists($cache) && filemtime($cache) > time() - 60*60){ | |
// If a cache file exists, and it is newer than 1 hour, use it | |
$instaData = json_decode(file_get_contents($cache)); | |
} else { | |
$instaData = json_decode((file_get_contents($result))); | |
file_put_contents($cache,json_encode($instaData)); | |
} | |
foreach ($instaData->data as $post) { | |
if(empty($post->caption->text)) { | |
// Do Nothing | |
} | |
else { | |
echo '<a class="instagram-unit" target="blank" href="'.$post->link.'"> | |
<img src="'.$post->images->low_resolution->url.'" alt="'.$post->caption->text.'" width="100%" height="auto" /> | |
<div class="instagram-desc">'.htmlentities($post->caption->text).' | '.htmlentities(date("F j, Y, g:i a", $post->caption->created_time)).'</div></a>'; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment