requirements: use Github V3 version of API to get the number of items of a user"s star.
and user"s api does not provide the number of star separately, but provides such an interface
" starred_url ":" https://api.github.com/users/tj/starred{/owner}{/repo}"
check . Github api uses paging technology. If you use the above default interface, you can only return up to 30 items. Therefore, you need to use parameters to obtain: https://api.github.com/users/tj/starred?page=1&per_page=100
Magi perturbed page can be up to 100.
that means I need to GET multiple interfaces like this until the acquired interface returns []
:
axios.get (`/ users/$ {app.userName} / starred?page=$ {iPP} & per_page= 100`)
loop is executed synchronously, and the GET request is obtained asynchronously. However, my loop variables are related to the data obtained asynchronously! So how do you write the loop code?
here is the code I wrote with recursion, but very slowly. This is demo , you can type tj to try, very slow.
let starredLists = []
!function getStarred(index){
axios.get(`/users/${app.userName}/starred?page=${indexPP}&per_page=100`)
.then(function(response){
starredLists.push(...response.data)
console.log(starredLists.length + " " + index)
if(response.data.length == 100)
getStarred(index);
if(response.data.length != 100)
app.stars = starredLists.length;
})
}(1)