javascriptnode.jstwitter-bootstraptwittertwitter-follow

NodeJS Twitter API client returns different next_cursor and next_cursor_str values


I am working with Twitter API ( in Node ) and trying to get the followers. As Twitter as has added cursor in its response I am easily getting first 20 followers but as soon as I try to update my cursor it redirects me to the first page. Need help to update the cursor.

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 );
    }
  });
}

I am also getting different next_cursor and next_cursor_str value

I am also getting different next_cursor and next_cursor_str value.

Please suggest me what is wrong.


Solution

  • The error is a result of an undefined cursor parameter. The Twitter API documentation for cursors defines routes with cursors like this:

    url_with_cursor = api_path + "&cursor=" + cursor

    The route must have &cursor= at the end.

    You should refactor the url to define a cursor:

    var url = 'followers/list.json?count=5000&cursor=' + cursor;