Skip to content

Instantly share code, notes, and snippets.

@sageworksstudio
Created June 2, 2016 23:37
Show Gist options
  • Save sageworksstudio/50bd84a2319ece97e5677a26e042d235 to your computer and use it in GitHub Desktop.
Save sageworksstudio/50bd84a2319ece97e5677a26e042d235 to your computer and use it in GitHub Desktop.
public function getInstagram($count=3) {
$user_id = 'YOUR-USER-ID';
$token = 'YOUR-TOKEN';
$cnt = (int) $count;
$url = "https://api.instagram.com/v1/users/{$user_id}/media/recent/?access_token={$token}&count={$count}";
$curl_connection = curl_init($url);
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl_connection);
if ($result === false) {
// die quietly
} else {
$feed = json_decode($result);
$rtn = ArrayList::create();
foreach ($feed->data as $img) {
$item = array('Image' => $img->images->thumbnail->url, 'Link' => $img->link, 'Caption' => $img->caption->text);
// $item = array('Link' => $img->link);
$rtn->push($item);
}
return $rtn;
}
curl_close($curl_connection);
return false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment