简体   繁体   English

通过Instagram API使用php获取照片和喜欢的照片

[英]Get photos and likes with php via Instagram API

While using an Instagram client_id API request like here: 在使用Instagram client_id API请求时,如下所示:

https://api.instagram.com/v1/users/ {user-id}/media/recent/?client_id=YOUR-CLIENT_ID https://api.instagram.com/v1/users/ {user-id} / media / recent /?client_id = YOUR-CLIENT_ID

I can actually SEE both the image url and like-count in the JSON response, but can't figure out how to extract both. 我实际上可以在JSON响应中看到图像url和like-count,但无法弄清楚如何同时提取两者。 I can only seem to extract the image itself like so: 我似乎只能像这样提取图像本身:

<?php
if (!empty($_GET['user_id'])){
    $user_id = ($_GET['user_id']);

    // connect to the instagram API
  $instagram_url = 'https://api.instagram.com/v1/users/' . $user_id . '/media/recent/?client_id=MY-CLIENT-ID';
  $instagram_json = file_get_contents($instagram_url);
  $instagram_array = json_decode($instagram_json, true);
}
?>

-- -

<?php
  if(!empty($instagram_array)){
    foreach($instagram_array['data'] as $key=>$image){
      echo '<img src="'.$image['images']['standard_resolution']['url'].'" alt=""/><br>';
    }
  }
?>

ps - this is all cobbled together from various tutorials etc. I am total noob, so a little hand-holding would be appreciated:) ps-这些内容都来自各种教程等。我完全是菜鸟,所以请稍稍动手:)

您应该能够像这样访问喜欢的图片数量: $image['likes']['count']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM