Twitch API最多显示60条记录和一个用于分页的_next光标。我找不到一种使用map函数在React中使用光标映射所有结果的方法。

  componentDidMount() {
    this.getComments();
  }

  getComments(){
    const api = 'https://api.twitch.tv/v5/videos/'+ this.state.value +'/comments?client_id='+ this.state.cid;
    fetch(api, {
      method: 'get',
      headers: {"Client-ID": this.state.cid}
    })
    .then((response) => response.text())
      .then((responseText) => {
        this.setState({hits : (JSON.parse(responseText)), api: api})
     });
   }



   render(){

    const { hits } = this.state;
    console.log({hits});

    return (
      <div>
         <ul id="results">
           { hits && hits.comments && hits.comments.length !== 0 ?
                 hits.comments.map(hit =>
                   <li key={hit._id}>
                     <span>[{this.convertSeconds(hit.content_offset_seconds)}] - {hit.message.body}</span>
                   </li>
                 )
              :
                 <div>No Comments Found</div>
           }
         </ul>
     </div>
    );
  }


如何通过这种映射技术使用_next游标进行映射?
还是有其他方法可以实现?

以下是JSON响应。

javascript - 如何使用游标从Twitch API映射所有结果-React-LMLPHP

最佳答案

要获得分页响应,您需要再次调用Twitch API,并将光标在after查询参数或before查询参数中传递给您的twitch调用。

范例-

const api = 'https://api.twitch.tv/v5/videos/<CLIENT_ID>?after=<NEXT_CURSOR>

07-24 17:49
查看更多