我在网上到处找,真不敢相信我找不到问题的答案。我想在我的网站上显示最新的单曲instagram照片。就这么简单。
没有画廊,没有幻想盒,没有幻灯片等
我发现了这个有用的链接:http://www.blueprintinteractive.com/blog/how-instagram-api-fancybox-simplified
它确实有效,但它没有提供你想显示多少图像的选项我只想要一张最新的instagram图片。
有人有主意吗?
感谢
您可以在显示第一张图像后break
foreach
,如下所示:
foreach ($result->data as $post) {
// Do something with this data.
break; // for one result only
}
或在url
末尾添加&count=1
,如下所示
https://api.instagram.com/v1/users/ID-GOES-HERE/media/recent/?access_token=TOKEN-GOES-HERE&count=1
答案就在这里:http://instagram.com/developer/endpoints/users/#get_users_media_recent_with_client_id
介质数量的计数选项!
试试这个:
$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
嵌入整个帖子可能是一个解决方案:
$json_post = @file_get_contents('https://api.instagram.com/oembed/?url=' . $indata->data[0]->link);
$oembed = json_decode($json_post, true);
echo $oembed['html'];
祝你好运!