Pablo Malynovytch Pablo Malynovytch - 9 months ago 34
PHP Question

It is possible get the medio of another user? Instgram API

This code that I took form another web, works! but only when I put my Instragram ID. Otherwise when I want to get a media from another user (changing the variable userid) it stops working.

To be sure I use to get the user ID.
And to get the Access Token (only with my account):

// Supply a user id and an access token
$userid = "-----";
$accessToken = "---";

// Gets 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);
return $result;
// Pulls and parses data.
$result = fetchData("{$userid}/media/recent/?access_token={$accessToken}");
$result = json_decode($result);
<?php if(!empty($result->data)): ?>
<?php foreach ($result->data as $post): ?>
<!-- Renders images. @Options (thumbnail,low_resoulution, high_resolution) -->
<a class="group" rel="group1" href="<?= $post->images->standard_resolution->url ?>"><img src="<?= $post->images->thumbnail->url ?>"></a>
<?php endforeach ?>
<?php endif ?>

Answer Source

The link you posted clearly indicates that the token only works with your own images.

In order to display your Instagram photos on your own website, you are required to provide an Instagram Access Token.

You should try a different API or method to show images from another user.