LouisVuittonDon
LouisVuittonDon

Reputation: 23

Why am I unable to get a specific ID from this array of IDs?

I'm using an NPM package called Twit to get a list of IDs that follow a specific twitter user

T.get('followers/ids', { screen_name: 'kanyewest' },  function (err, data, response) {
  console.log(data)
})

outputs:

root@box:/var/app/twitterbot# screen -r twitterbot
     793990194311626800,
     902628660292837400,
     937381447303823400,
     966061750650069000,
     143239761,
     396278761,
     949690872429387800,
     880529987392204800,
     142651429,
     31053983,
     757696951659921400,
     879346525666762800,
     1651454588,
     927660101279903700,
     737929151907287000,
     933093234590466000,
     114504331,
     1104837235,
     ... 4900 more items ],
  next_cursor: 1598483705781998800,
  next_cursor_str: '1598483705781998810',
  previous_cursor: 0,
  previous_cursor_str: '0' }

However, if I do:

T.get('followers/ids', { screen_name: 'kanyewest' },  function (err, data, response) {
  console.log(data[1])
})

I get undefined.

What am I doing wrong?

Upvotes: 0

Views: 32

Answers (1)

Marcos Casagrande
Marcos Casagrande

Reputation: 40424

data is an object, not an array, the ids are available at data.ids which is an array of ids

T.get('followers/ids', { screen_name: 'kanyewest' },  function (err, data) {
   console.log(data.ids)
});

The package has an example on github where you can see how it's used.

Upvotes: 1

Related Questions