获取我的关注者列表,然后使用Instagram API [英] Getting a list of my followers and followed using Instagram API
问题描述
我正在尝试获取所有关注者以及使用Instagram API在Instagram上关注的每个人的列表.我认为每当我尝试吸引我的关注者时,我的回应就会返回null.
I'm trying to get a list of all my followers and everyone I follow on Instagram using the Instagram API. I think that my response is returning null whenever I try to get my followers.
这是我得到的错误:
无法读取未定义的属性'length'
Cannot read property 'length' of undefined
这是参考response.data.length
This is in reference to response.data.length
这是我的app.js:
Here's my app.js:
window.Instagram = {
/**
* Store application settings
*/
config: {},
BASE_URL: 'https://api.instagram.com/v1',
init: function(opt) {
opt = opt || {};
this.config.client_id = opt.client_id;
},
/**
* Get a list of popular media
*/
popular: function(callback) {
var endpoint = this.BASE_URL + '/media/popular?client_id=' + this.config.client_id;
this.getJSON(endpoint, callback);
},
/**
* Get a list of recently tagged media
*/
tagsByName: function(name, callback) {
var endpoint = this.BASE_URL + '/tags/' + name + '/media/recent?client_id=' + this.config.client_id;
this.getJSON(endpoint, callback);
},
followers: function(callback) {
var endpoint = this.BASE_URL + '/users/self/follows?access_token=' + this.config.access_token;
this.getJSON(endpoint, callback);
},
getJSON: function(url, callback) {
$.ajax({
type: 'GET',
url: url,
dataType: 'jsonp',
success: function(response) {
if (typeof callback === 'function') callback(response);
}
});
}
}
Instagram.init({
client_id: 'CENSORED',
access_token: 'CENSORED'
});
$(document).ready(function() {
Instagram.followers(function(response) {
var $instagram = $('#instagram');
$instagram.append('<textarea cols="1" rows="' + response.data.length + '">')
for (var i = 0; i < response.data.length; i++) {
var name = response.data[i].username;
$instagram.append(name + ' ');
}
$instagram.append('</textarea>');
});
});
推荐答案
您是否处于沙盒模式?如果是这样,则期望得到空响应,请阅读有关沙盒模式的文档: https://www.instagram .com/developer/sandbox/
Are you in sandbox mode? if so it is expected to get empty response, read documentation about Sandbox mode: https://www.instagram.com/developer/sandbox/
(我还注意到您有'/media/popular?client_id='
的代码,自2016年6月1日起不再使用流行的API,因此您可能正在使用一些旧的Instagram库代码.-您需要阅读更新的文档并重新实现所有功能)
(Also I noticed you have code for '/media/popular?client_id='
, the popular API was deprecated as of June 1st 2016, so you probably are using some old Instagram library code. - You need to read updated documentation and re-implement everything)
这篇关于获取我的关注者列表,然后使用Instagram API的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!