有可能获得另一个用户的媒体吗? Instgram API

时间:2016-10-26 14:52:49

标签: php api web instagram-api

我从另一个网站上获取此代码,有效!但只有当我把我的Instragram ID。否则,当我想从另一个用户获取媒体时(更改变量userid),它将停止工作。

确保我使用https://www.otzberg.net/iguserid/index.php来获取用户ID。 并获取访问令牌(仅限我的帐户):http://instagram.pixelunion.net/

<?php
    // 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);
         curl_close($ch); 
         return $result;
    }
    // Pulls and parses data.
    $result = fetchData("https://api.instagram.com/v1/users/{$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 ?>

1 个答案:

答案 0 :(得分:0)

您发布的链接清楚地表明该令牌仅适用于您自己的图片。

  

要在您的自己的网站上显示您的 Instagram照片,   您需要提供Instagram访问令牌。

您应该尝试使用其他API或方法来显示其他用户的图片。