如何从 Instagram 获取我最近的照片?

How to get my recent photos from Instagram?

我阅读了 instargam API 并搜索了 google 中的代码,但没有得到满足我要求的任何确切解决方案。我想在我的网站上显示我最近的照片,例如 Facebook 插件。我的图片看起来像 -

我尝试关注 URL,但出现错误。你能检查一下吗 -

https://api.instagram.com/v1/tags/nofilter/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d

https://api.instagram.com/v1/users/user-id/media/recent/?access_token=72020554b1884a9691352d4cd9759951

请建议我如何显示我最近的照片,如上图所示?

编辑: 我有 Client IDClient Secreat。让我知道哪个是 Access Token?

fb2e77d.47a0479900504cb3ab4a1f626d174d2d -> 这是您需要获取自己的访问令牌的 instagram 示例。

替换数组中的值。

'client_id' ; 'client_secret'; 'redirect_uri' and 'code'

client_id: 您的客户编号
client_secret: 你的客户端密码
grant_type:authorization_code是目前唯一支持的值
redirect_uri:您在授权请求中使用的redirect_uri。注意:这必须与授权请求中的值相同。
代码: 您在授权步骤中收到的确切代码。

阅读官方文档(Instagram Dev. ) 第一步:将您的用户引导至我们的授权 URL 和 第二步:从 Instagram 接收重定向(此处获取代码) .

$apiData = array(
  'client_id'       => $client_id,
  'client_secret'   => $client_secret,
  'grant_type'      => 'authorization_code',
  'redirect_uri'    => $redirect_uri,
  'code'            => $code
);

$apiHost = 'https://api.instagram.com/oauth/access_token';

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $apiHost);
curl_setopt($ch, CURLOPT_POST, count($apiData));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($apiData));
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$jsonData = curl_exec($ch);
curl_close($ch);

var_dump($jsonData);
$user = @json_decode($jsonData); 


print_r($user);

您可以查看官方页面。 Instagram Dev.

我用过这个API请查收。我相信这会对你有所帮助。

<?php
$access_token = 'YOUR_3rd_PARTY_ACCESS_TOKEN';
$user_id = 'INSTAGRAM_USER_ID';
$json_profile = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/?access_token={$access_token}");
$json = file_get_contents("https://api.instagram.com/v1/users/{$user_id}/media/recent/?access_token=" . $access_token . "&count=9");
$a_json_profile = json_decode($json_profile, true);
$a_json = json_decode($json, true);
//echo "<pre>";
//print_r($json2);
//echo "</pre>"; exit;
$i = 0;
foreach ($a_json['data'] as $key => $value) {
    //if ($i < 9) {
    $a_images[$i]['link'] = $value['link'];
    $a_images[$i]['url'] = $value['images']['thumbnail']['url'];
    //$a_images[$value['id']]['caption'] = $value['caption']['text'];

    $i++;
    //}
}
shuffle($a_images);
$finalData = array('info'=>$a_json_profile, 'images'=>$a_images);
echo json_encode($finalData);
exit;