因此,我的任务是从用户的存储库中获取所有问题。
为此,我要这样做
axios.get(`https://api.github.com/repos/${user}/${repo}/issues?state=all`)
.then((response) => {
console.log(response);
})
.catch((err) => console.log(err));
};
问题是,我还需要对问题进行分页,但response
没有任何关于问题数量的信息。它只有一系列问题。我想只有30个第一个
我尝试使用不同的路径,例如搜索路径
axios.get(`https://api.github.com/search/issues?q=${user}+${repo}&per_page=10`)
但是它给了我完全不同的结果,尽管它确实返回了总计数。
所有的帮助都将不胜感激。
为了便于示例发出api请求,您可以使用Facebook
作为用户参数,使用React
作为存储库参数
发布于 2019-09-14 21:10:52
看起来github提供了一个链接头,它将为您提供该信息:https://developer.github.com/v3/#pagination
链接头包括分页信息:
Link: <https://api.github.com/user/repos?page=3&per_page=100>; rel="next",
<https://api.github.com/user/repos?page=50&per_page=100>; rel="last"
发布于 2019-09-14 21:25:21
使用分页的react js repo:https://api.github.com/repos/facebook/react/issues示例:https://api.github.com/repos/facebook/react/issues?page=2
有关更多选项,请阅读docs
axios.get(`https://api.github.com/repos/${user}/${repo}/issues?page=${page}&per_page=10`)
.then((response) => {
console.log(response);
})
.catch((err) => console.log(err));
};
带有GraphQL的v4
阅读此article
GraphQL查询:
query {
repository(owner:"facebook", name:"react") {
issues(states:OPEN) {
totalCount
}
}
}
https://stackoverflow.com/questions/57934969
复制相似问题