我通过 jQuery 使用位置 lat/lon 参数创建了一个 Instagram 请求。我将返回所有相关的缩略图,最多 100 个,以及:
- 标题 = 标题,如果标题不为空(鼠标悬停时)
- 发布图片的用户。
- 发布日期图像。
- standard_resolution.url 的超链接(点击缩略图)
以下请求返回缩略图、用户和发布日期。但是,当鼠标悬停并单击时,stardard_resolution.url 的标题/标题和超链接不会显示。
我相信我的追加语句语法是错误的,但无法弄清楚。这是代码和 FIDDLE
(function ($) {
$(document).ready(function () {
var count = "100";
var access_token = "<REMOVED BY CATSHOES - IS THIS SUPPOSED TO BE SECRET?>";
var access_parameters = {
access_token: access_token
};
function grabImages(access_parameters) {
var instagramUrl = "https://api.instagram.com/v1/media/search?lat=19.951204000000&lng=-155.860291000000&name=xxx&distance=400&callback=?&count=" + count;
$.getJSON(instagramUrl, access_parameters, onDataLoaded);
}
function onDataLoaded(instagram_data) {
if (instagram_data.meta.code == 200) {
var photos = instagram_data.data;
if (photos.length > 0) {
for (var key in photos) {
var photo = photos[key];
var a_href = photo.images.standard_resolution.url;
var img_title = "";
var date = new Date(parseInt(photo.created_time) * 1000);
if (photo.caption != null) {
img_title = photo.caption.text;
}
$("#target").append('<a class="preview" href="' + a_href + "' title='" + img_title + '" ></a> <img src ="' + photo.images.thumbnail.url + '"><div>\
' + "Posted by: ", photo.user.full_name + '<br />\
' + "Posted on: ", (date.getMonth() + 1) + "/" + date.getDate() + "/" + date.getFullYear() + '<br />\
</div />');
}
} else {
$("#target").append("Currently no Instagram photos for this location.");
}
} else {
var error = data.meta.error_message;
$("#target").append('Photos for this location will display soon. Instagram message: ' + error);
}
}
grabImages(access_parameters);
});
})(jQuery);