我已经编写了一些代码来使用 instagram graph api 从 instagram 中提取图像。一切正常,但性能很慢。我正在使用 JavaScript,但遇到了同样的问题,但 PHP 更糟。我是新手,对此缺乏经验,任何建议都会很棒。
下面是代码:
$.getJSON(instagram_url_1, function(data) {
instagram_array_1 = data['data'];
instagram_next = data['paging'];
instagram_next = instagram_next['next'];
for (var image_count = 0; image_count < 25; image_count++) {
image_data = instagram_array_1[image_count];
image_data = image_data['id'];
image_link = 'https://graph.facebook.com/' + image_data + '?fields=media_url&access_token=' + access_token;
image_array[image_count] = image_link;
};
$.getJSON(instagram_next, function(data) {
instagram_array_2 = data['data'];
for (image_count = 0; image_count < 25; image_count++) {
image_data = instagram_array_2[image_count];
image_data = image_data['id'];
image_link = 'https://graph.facebook.com/' + image_data + '?fields=media_url&access_token=' + access_token;
image_array[image_count + 25] = image_link;
};
console.log(image_array);
for (var image_count = 0; image_count < 40; image_count++) {
image_link_array = image_array[image_count];
$.getJSON(image_link_array, function(data) {
image_link = data['media_url'];
image_html = '<img class="instagram-images" src=' + image_link + ' />';
$('#instagram-body').append(image_html);
});
};
});
});
该网站可能需要一些时间来加载,而不是年龄但足够我想尝试简化它以改善用户体验。提前致谢!