【问题标题】:Why am I unable to get a specific ID from this array of IDs?为什么我无法从这个 ID 数组中获取特定 ID?
【发布时间】:2018-10-02 22:19:17
【问题描述】:

我正在使用一个名为 Twit 的 NPM 包来获取关注特定 Twitter 用户的 ID 列表

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

输出:

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' }

但是,如果我这样做:

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

我不确定。

我做错了什么?

【问题讨论】:

  • console.log(data, response)的输出是什么;
  • @MarcosCasagrande 此处粘贴时间过长pastebin.com/Cnti1Fqx

标签: javascript arrays node.js object indexing


【解决方案1】:

data 是一个对象,而不是一个数组,id 可以在data.ids 获得,这是一个 id 数组

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

该软件包在 github 上有一个 example,您可以在其中查看它的使用方式。

【讨论】:

  • @LouisVuittonDon 如果成功,记得采纳答案
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-06-22
  • 1970-01-01
  • 1970-01-01
  • 2017-07-03
  • 2022-09-28
  • 1970-01-01
  • 2017-10-16
相关资源
最近更新 更多