通过Instagram API使用php获取照片和喜欢的照片 [英] Get photos and likes with php via Instagram API

查看:117
本文介绍了通过Instagram API使用php获取照片和喜欢的照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Instagram client_id API请求时,如下所示:

While using an Instagram client_id API request like here:

https://api.instagram.com/v1/users/ {user- id}/media/recent/?client_id =您的客户ID

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

我实际上可以在JSON响应中看到图像url和like-count,但无法弄清楚如何同时提取两者.我似乎只能像这样提取图像本身:

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-各种教程等都将它们拼凑在一起.我完全是菜鸟,因此请稍稍动手:)

ps - this is all cobbled together from various tutorials etc. I am total noob, so a little hand-holding would be appreciated:)

推荐答案

您应该能够访问喜欢的图像数量,例如:$image['likes']['count']

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

这篇关于通过Instagram API使用php获取照片和喜欢的照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆