问题
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