gpt4 book ai didi

javascript - 获取我的关注者列表并使用 Instagram API 关注

转载 作者:行者123 更新时间:2023-11-29 23:56:25 25 4
gpt4 key购买 nike

我正在尝试使用 Instagram API 获取我的所有关注者以及我在 Instagram 上关注的所有人的列表。我认为每当我尝试吸引我的关注者时,我的响应都会返回 null。

这是我得到的错误:

Cannot read property 'length' of undefined

这是引用response.data.length

这是我的 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 + '&#13;&#10;');
}
$instagram.append('</textarea>');
});

});

最佳答案

您是否处于沙盒模式?如果是这样,预计会得到空响应,请阅读有关沙盒模式的文档:https://www.instagram.com/developer/sandbox/

(我还注意到您有用于 '/media/popular?client_id=' 的代码,自 2016 年 6 月 1 日起,流行的 API 已被弃用,因此您可能正在使用一些旧的 Instagram 库代码。 - 你需要阅读更新的文档并重新实现所有内容)

关于javascript - 获取我的关注者列表并使用 Instagram API 关注,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41496649/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com