Вопрос

I am looking all over the web and can't believe I can't find an answer to my question. I would like to display the latest single instagram photo on my website. simple as that.

No gallery, no fancybox, no slideshow etc etc

I found this useful link: http://www.blueprintinteractive.com/blog/how-instagram-api-fancybox-simplified

it's actually working but it doesn't give an option of how many images you would like to display and I would like only one latest instagram image.

anyone have an idea?

Thanks

Это было полезно?

Решение

You can break foreach after showing first image like below:

foreach ($result->data as $post) {
  // Do something with this data.
  break; // for one result only
}

Or add &count=1 at end of url as below

https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE&count=1

Другие советы

The answer is right here: http://instagram.com/developer/endpoints/users/#get_users_media_recent_with_client_id

Count option for number of media !

Try this:

$page_id = 'YOUR ID';
$access_token = 'YOUR ACCESS TOKEN';
$json_object = @file_get_contents('https://api.instagram.com/v1/users/' . $page_id . 
'/media/recent/?access_token=' . $access_token . '&count=1');
$indata = json_decode($json_object);
echo $indata->data[0]->images->low_resolution->url // for low res
echo $indata->data[0]->images->thumbnail->url;      //for thumbnail
echo $indata->data[0]->images->standard_resolution->url; //for standard res
echo $indata->data[0]->caption->text; //for caption

Embedding the whole post may be a solution:

$json_post = @file_get_contents('https://api.instagram.com/oembed/?url=' . $indata->data[0]->link);
$oembed = json_decode($json_post, true);
echo $oembed['html'];

Good luck!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top