Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过Instagram API使用php获取照片和喜好_Php_Json_Instagram_Instagram Api - Fatal编程技术网

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

通过Instagram API使用php获取照片和喜好,php,json,instagram,instagram-api,Php,Json,Instagram,Instagram Api,使用Instagram客户端idAPI请求时,如下所示: {user id}/media/recent/?client\u id=YOUR-client\u id 实际上,我可以在JSON响应中看到图像url和like计数,但不知道如何提取两者。我似乎只能这样提取图像本身: <?php if (!empty($_GET['user_id'])){ $user_id = ($_GET['user_id']); // connect to the instagram API

使用Instagram
客户端id
API请求时,如下所示:

{user id}/media/recent/?client\u id=YOUR-client\u id

实际上,我可以在JSON响应中看到图像url和like计数,但不知道如何提取两者。我似乎只能这样提取图像本身:

<?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);
}
?>

--



ps-这些都是从各种教程等拼凑而成的。我完全是个傻瓜,所以如果你能稍微握一下手,我将不胜感激:)

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

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