通过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']