Javascript instagram API 显示20多张照片
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12311037/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Displaying more than 20 photos in instagram API
提问by PhDeOliveira
I've been doing some research and trying to figure out how to display more then 20 images that are being pulld in from the instagram api. I'm pretty new at this so any help would be appreciated! Just trying to see if there are any work arounds? Saw something about adding pagination that could possibly help.. if thats the case details on how to do that would be great too!
我一直在做一些研究,并试图弄清楚如何显示从 instagram api 中提取的超过 20 张图像。我在这方面很新,所以任何帮助将不胜感激!只是想看看是否有任何解决方法?看到了一些关于添加分页可能会有所帮助的内容......如果是这样的话,关于如何做到这一点的细节也会很棒!
Here's the code I have so far.
这是我到目前为止的代码。
<script type="text/javascript">
$.ajax({
type: "GET",
dataType: "jsonp",
cache: false,
url: "https://api.instagram.com/v1/tags/coffee/media/recent?client_id=[]&access_token=[]",
success: function(data) {
for (var i = 0; i < 20; i++) {
$(".instagram").append("<a class='big-square span2' target='_blank' href='" + data.data[i].link +"'><img src='" + data.data[i].images.low_resolution.url +"'></img></a>");
}
}
});
</script>
回答by tcd
Instagram has a 20 image limit on their API, check out this thread and my answer:
Instagram 在他们的 API 上有 20 张图片的限制,看看这个帖子和我的回答:
What is the maximum number of requests for Instagram?
EDIT: also, have a look at THIS
编辑:还有,看看这个
回答by Dariush Salami
Any app created before Nov 17, 2015 will continue to function until June 2016. After June 2016, the app will automatically be moved to Sandbox Mode if it wasn't approved through the review process.
Sandbox mode are real Instagram data (i.e. what is normally visible in the Instagram app), but with the following conditions:
在 2015 年 11 月 17 日之前创建的任何应用程序将继续运行到 2016 年 6 月。2016 年 6 月之后,如果未通过审核流程,该应用程序将自动移至沙盒模式。
沙盒模式是真实的 Instagram 数据(即通常在 Instagram 应用程序中可见的数据),但具有以下条件:
- Apps in sandbox are restricted to 10 users
- Data is restricted to the 10 users and the 20 most recent media from each of those users
- Reduced API rate limits
- 沙箱中的应用程序限制为 10 个用户
- 数据仅限于 10 个用户和每个用户的 20 个最新媒体
- 降低 API 速率限制
回答by hayk.mart
Try adding &count=N
to the request, where N is the number of results you want.
尝试添加&count=N
到请求中,其中 N 是您想要的结果数。
回答by liding
Try this code
试试这个代码
$api = "https://api.instagram.com/v1/tags/snow/media/recent?client_id=".$client;
function get_curl($url) {
if(function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
$output = curl_exec($ch);
echo curl_error($ch);
curl_close($ch);
return $output;
} else{
return file_get_contents($url);
}
}
while ($api !== NULL) {
$response = get_curl($api);
foreach(json_decode($response)->data as $item){
$src = $item->images->standard_resolution->url;
$thumb = $item->images->thumbnail->url;
$url = $item->link;
$images[] = array(
"src" => htmlspecialchars($src),
"thumb" => htmlspecialchars($thumb),
"url" => htmlspecialchars($url)
);
echo "<a href='".$src."'><img src='".$thumb."' width='150' height='150' border='0'></a> ";
}
$api = json_decode($response)->pagination->next_url;
}
回答by Jochem Schulenklopper
See http://instagram.com/developer/endpoints/. It details the generics of the endpoints, also listing the pagination attributes. In short, a 'paginated' response will include a next_url
that can be used to retrieve the next set of results. Subsequentially retrieving all next URLs (as long as they are supplied in the result) will get you the complete set.
请参阅http://instagram.com/developer/endpoints/。它详细说明了端点的泛型,还列出了分页属性。简而言之,“分页”响应将包括next_url
可用于检索下一组结果的 。随后检索所有下一个 URL(只要它们在结果中提供)将为您提供完整的集合。
BTW, you can try to increase the count
parameter in the request. (Depending on the Instagram library you are using, such things can be supplied via an options
hash or something similar.) That might save you a couple of extra requests. The page I just mentioned doesn't specify a maximum count value though. I suspect that Instagram is changing the maximum dynamically, and per endpoint.
顺便说一句,您可以尝试增加count
请求中的参数。(根据您使用的 Instagram 库,可以通过options
哈希或类似的东西提供此类内容。)这可能会为您节省一些额外的请求。我刚刚提到的页面没有指定最大计数值。我怀疑 Instagram 正在动态更改每个端点的最大值。
回答by d4nyll
You can get more than 20 items by specifying a count
parameter and set it to the number you want.
您可以通过指定一个count
参数并将其设置为您想要的数量来获取 20 多个项目。
However, Instagram also imposes an undocumented limit of 33 for every request you make, and so you'd have to paginate if you get more than 33.
但是,Instagram 还对您提出的每个请求施加了 33 个未记录的限制,因此如果您收到超过 33 个请求,则必须进行分页。
However, I have written Instafetchwhich will help you paginate, it will even filter media by tags for you. So feel free to use it!
但是,我编写了Instafetch,它可以帮助您进行分页,它甚至可以为您按标签过滤媒体。所以请放心使用它!
回答by Achira Shamal
回答by kenai37
<script>
var token = 'your_token',
userid = your_id,
num_photos = 12;
$.ajax({
url: 'https://api.instagram.com/v1/users/'+userid+'/media/recent',
dataType: 'jsonp',
type: 'GET',
data: {access_token: token, count: num_photos},
success: function(data){
console.log(data);
},
error: function(data){
}
});
</script>
https://rudrastyh.com/javascript/get-photos-from-instagram.html
https://rudrastyh.com/javascript/get-photos-from-instagram.html
回答by user3632055
Actually, there is a chance to get the next 20 pictures, and after that the next 20 and so on... In the JSON responce there is an "pagination" array:
实际上,有机会获得接下来的 20 张图片,然后是接下来的 20 张等等......在 JSON 响应中有一个“分页”数组:
"pagination":{
"next_max_tag_id":"1411892342253728",
"deprecation_warning":"next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead",
"next_max_id":"1411892342253728",
"next_min_id":"1414849145899763",
"min_tag_id":"1414849145899763",
"next_url":"https:\/\/api.instagram.com\/v1\/tags\/lemonbarclub\/media\/recent?client_id=xxxxxxxxxxxxxxxxxx\u0026max_tag_id=1411892342253728"
}
this is the information on specific API call and the object "next_url" shows the URL to get the next 20 pictures so just take that URL and call it for the next 20 pictures...
这是有关特定 API 调用的信息,对象“ next_url”显示了获取接下来 20 张图片的 URL,因此只需获取该 URL 并为接下来的 20 张图片调用它...
for more information about Instagram API check this out: https://medium.com/@KevinMcAlear/getting-friendly-with-instagrams-api-abe3b929bc52
有关 Instagram API 的更多信息,请查看:https: //medium.com/@KevinMcAlear/getting-friendly-with-instagrams-api-abe3b929bc52
回答by Srikukan Ajith
You can use Instagram feeds libraries like instafeed. It allows to get feed of 60 images (maximum)
您可以使用 Instagram 提要库,例如instafeed。它允许获取 60 张图像(最大)
Eg:
例如:
<script type="text/javascript">
var feed = new Instafeed({
get: 'tagged',
tagName: 'awesome',
limit: 20,
clientId: 'YOUR_CLIENT_ID'
});
feed.run();
</script>
limit (number) - Maximum number of Images to add. Max of 60.
limit (number) - 要添加的最大图像数。最多 60 个。