Wednesday, February 28, 2018

Get image from instagram by api code.

<?php
$userid = "1367761071";
$accessToken = "1367761071.5b9e1e6.7651f16d557948a598176b957c35c693";
$url = "https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}";
$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);
$result = json_decode($result);
?>

<ul>
<?php $i=1; foreach ($result->data as $post): ?>
    <?php  if($i>5){ break;} ?>
    <li><a class="" href="<?php echo $post->images->standard_resolution->url ?>" data-fancybox-group="gallery" title="<?php echo $post->caption->text ?>"><img src="<?php echo $post->images->thumbnail->url ?>" width="246" height="246" alt="<?php echo $post->caption->text ?>" /></a> </li>

<?php $i++; endforeach; ?>
</ul>
</div>

No comments:

Post a Comment