Created
January 3, 2017 17:46
-
-
Save faiyazalam/827a109eb6e365640c388224e1d51a31 to your computer and use it in GitHub Desktop.
Get recent images from Instagram using PHP & cURL
This file contains hidden or 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 | |
/** | |
* Supply a user id and an access token | |
* Jelled explains how to obtain a user id and access token in the link provided | |
* @link http://jelled.com/instagram/access-token | |
*/ | |
$userid = ""; | |
$accessToken = ""; | |
// Get our data | |
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; | |
} | |
// Pull and parse data. | |
$result = fetchData("https://api.instagram.com/v1/users/{$userid}/media/recent/?access_token={$accessToken}"); | |
$result = json_decode($result); | |
?> | |
<?php $limit = 8; // Amount of images to show ?> | |
<?php $i = 0; ?> | |
<?php foreach ($result->data as $post): ?> | |
<?php if ($i < $limit ): ?> | |
<a href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->standard_resolution->url ?>" width="500" height="500"></a> | |
<?php $i ++; ?> | |
<?php endif; ?> | |
<?php endforeach; ?> |
access token is terminated by instagram. so the code is not working anymore...
Script made based on the new (2020) Instagram API -> https://github.com/ribeiroeder/php-curl-instagram-graph
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am getting error like
Notice: Trying to get property of non-object in C:\xampp\htdocs\raj\insta_image.php on line 36
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\raj\insta_image.php on line 36