NodeJS Twitter API客户端返回不同的next_cursor和next_cursor_str值
问题描述:
我正在使用Twitter API(在节点中)并尝试获取关注者。由于Twitter在其响应中添加了光标,我很容易获得前20位追随者,但只要我尝试更新光标,就会将我重定向到第一页。需要帮助来更新游标。NodeJS Twitter API客户端返回不同的next_cursor和next_cursor_str值
var cursor = -1;
mainEmployee(params, cursor);
function mainEmployee(params, cursor) {
console.log(cursor);
var url = 'followers/list.json?count=5000&' + cursor;
console.log(url);
client.get(url, params, function(error, followers, response) {
if(!error) {
// console.log(cursor);
// for(var i = 0; i < followers.users.length; i++) {
// followersData(followers.users[i]);
// }
// console.log(followers);
var new_cursor = followers.next_cursor_str;
if(cursor != 0)
mainEmployee(params, new_cursor);
else
console.log("cursor is empty");
}
else {
console.log(error);
}
});
}
我也越来越不同next_cursor
和next_cursor_str
值。
请告诉我什么是错的。
答
该错误是由于未定义的cursor
参数造成的。该Twitter API documentation for cursors定义路由像这样光标:
url_with_cursor = api_path + “&光标=” +光标
的路由必须在端部具有&cursor=
。
你应该重构url
定义游标:
var url = 'followers/list.json?count=5000&cursor=' + cursor;
感谢@gnerkus我得到了我的错误 –
不客气。如果它解决了你的问题,你能选择这个作为接受的答案吗?它将帮助未来的访问者解决这个问题。 – gnerkus