列出GitHub用户及其转发计数



我想列出使用GitHub rest API的GitHub用户及其转发计数。

我尝试在简单节点应用程序中使用axios发送请求(https://api.github.com/search/users?q=${q}&&per_page=${COUNTS_PER_PAGE}&&page=${page || 1}(。但除了repos_url之外,没有与回购相关的字段响应。

所以我尝试再次向每个用户发送repos_url请求,但超过了速率限制。

有人帮我解决这个问题吗?任何帮助对我都有帮助。

我在抓取我参与的一个组织时遇到了同样的问题。我们解决这个问题的方法是使用python并执行try/except块来不断尝试。

while True:
params = {"cursor": endCursor}
try:
response = get_repos(params)
except Exception:
rand_sleep = randint(5, 30)
print(f"Gonna sleep for {rand_sleep} because of a 403 error...")
sleep(rand_sleep)
repos = response['organization']['repositories']['nodes']
all_repos = all_repos + repos
hasNextPage = response['organization']['repositories']['pageInfo']['hasNextPage']
endCursor = response['organization']['repositories']['pageInfo']['endCursor']

我们利用https://api.github.com/graphql端点来获取我们需要的数据,然后不断地尝试获取数据块。

可以使用superface sdk检索repo计数,而不是使用axios手动调用api。sdk处理与github API的通信并返回回购列表,然后您可以从中获取编号。以下是的步骤

npm install @superfaceai/one-sdk
npx @superfaceai/cli install vcs/user-repos

const { SuperfaceClient } = require('@superfaceai/one-sdk');
const sdk = new SuperfaceClient();
async function run() {
// Load the installed profile
const profile = await sdk.getProfile('vcs/user-repos');
// Use the profile
const result = await profile
.getUseCase('UserRepos')
.perform({
user: 'superfaceai'
});
console.log(result.unwrap().repos.length);
}
run();

您可以让脚本在请求之间休眠,以应对速率限制的

最新更新