伙计我正在使用Instagrams API来获取具有特定标记的所有图像。
这是我的代码:
<?PHP
function callInstagram($url)
{
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 2
));
$result = curl_exec($ch);
curl_close($ch);
return $result;
}
$tag = 'sweden';
$client_id = "XXXX";
$url = 'https://api.instagram.com/v1/tags/'.$tag.'/media/recent?client_id='.$client_id;
$inst_stream = callInstagram($url);
$results = json_decode($inst_stream, true);
//Now parse through the $results array to display your results...
foreach($results['data'] as $item){
$image_link = $item['images']['thumbnail']['url'];
$Profile_name = $item['user']['username'];
echo '<div style="display:block;float:left;">'.$Profile_name.' <br> <img src="'.$image_link.'" /></div>';
}
使用此代码,我会获得20张带有sweden
标记的图片。
我需要知道如何为此标记获取min_tag_id
和max_tag_id
,以便我可以制作像分页一样的内容。
那么您能否告诉我如何获得最后一个帖子/图像的ID?
提前致谢!
答案 0 :(得分:1)
来自Instagram文档:
PAGINATION
Sometimes you just can't get enough. For this reason, we've provided a convenient way to access more data in any request for sequential data. Simply call the url in the next_url parameter and we'll respond with the next set of data.
{
...
"pagination": {
"next_url": "https://api.instagram.com/v1/tags/puppy/media/recent?access_token=fb2e77d.47a0479900504cb3ab4a1f626d174d2d&max_id=13872296",
"next_max_id": "13872296"
}
}
On views where pagination is present, we also support the "count" parameter. Simply set this to the number of items you'd like to receive. Note that the default values should be fine for most applications - but if you decide to increase this number there is a maximum value defined on each endpoint.
答案 1 :(得分:1)
Instagram的API返回带有“next_url”和“next_max_id”节点的“分页”键。修改您的代码,以便在$result['pagination']['next_url'] != ''
时继续循环。