Get photos and likes with php via Instagram API

我怕爱的太早我们不能终老 提交于 2019-12-08 09:13:30

问题


While using an Instagram client_id API request like here:

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. 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:)


回答1:


You should be able to access the images count of likes like this: $image['likes']['count']



来源:https://stackoverflow.com/questions/28523008/get-photos-and-likes-with-php-via-instagram-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!