Skip to content

Instantly share code, notes, and snippets.

@erickarbe
Created May 15, 2012 01:04
Show Gist options
  • Save erickarbe/2698356 to your computer and use it in GitHub Desktop.
Save erickarbe/2698356 to your computer and use it in GitHub Desktop.
Get Instagram Pics by tag via PHP
<?php
$client_id = "xxx"; //your client-id here
$tag = "kittens"; //your tag here
$cachefile = "instagram_cache/$tag.cache";
if (file_exists($cachefile) && time()-filemtime($cachefile)<3600) {
$contents = file_get_contents($cachefile);
} else {
$contents = file_get_contents("https://api.instagram.com/v1/tags/$tag/media/recent?client_id=$client_id");
file_put_contents($cachefile, $contents);
}
$json = json_decode($contents, true);
$i = 0;
foreach ($json["data"] as $value) {
echo echoimage($value);
if (++$i == 8) break;
}
function echoimage($value) {
$thumb = $value["images"]["thumbnail"]["url"];
$link = $value["link"];
$time = date("d/m/y", $value["created_time"]);
$nick = $value["user"]["username"];
$avatar = $value["user"]["profile_picture"];
return "<div class=\"thumb\"><a href=\"$link\" target=\"_blank\"><img src=\"$thumb\"/></a></div>";
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment