【发布时间】:2014-05-27 14:40:10
【问题描述】:
我使用下面的代码来获取我的 Instagram 帐户的关注者并在我的网站上显示个人资料图片。这工作正常。我还想做的是显示我网站上的关注者总数,这是我需要帮助的。
下面是完整的代码,如您所见,我已尝试使用“data.counts.followed_by”。这给了我以下错误:“Uncaught TypeError: Cannot read property 'followed_by' of undefined”。
我怎样才能实现我想要的?
$(document).ready(function() {
var $access_token = '{access-token}';
pollInstagram('https://api.instagram.com/v1/users/xxxxx/followed-by?access_token=xxxxx&count=15');
});
function pollInstagram(next_url, count){
$.ajax({
method: "GET",
url: next_url,
dataType: "jsonp",
jsonp: "callback",
jsonpCallback: "jsonpcallback",
success: function(data) {
$.each(data.data, function(i, item) {
console.log(data.counts.followed_by); <-----
var img = '<img style="width: 18%; margin-right: 7px;" src=' + data.data[i].profile_picture + ' />';
$('#show-images').append(img);
});
},
error: function(jqXHR, textStatus, errorThrown) {
//alert("Check you internet Connection");
$("#log").val($("#log").val() + 'Error\n');
}
});
}
【问题讨论】:
-
你试过
console.log(data)看看对象的结构吗?