简体   繁体   English

如何通过GitHub API列出用户的GitHub存储库

[英]How to list a user's GitHub repository via the GitHub API

I'm trying to list the private repositories of a user via the GitHub API. 我正在尝试通过GitHub API列出用户的私有存储库。 The request I'm currently making to GitHub is the following. 我目前向GitHub提出的请求如下。

https://api.github.com/users/username/repos?sort=updated&direction=desc&visibility=all

It does return the user's repositories but not the private ones. 它确实返回用户的存储库,但不返回私有存储库。 At first I thought that the problem was with the scopes options on my OAuth token. 起初我认为问题出在我的OAuth令牌上的范围选项上。 I currently have the following set in my application. 我目前在我的应用程序中有以下设置。

'user',
'repo',
'repo_deployment',
'admin:repo_hook',
'admin:org_hook',

But even if I set all of the scope option on my dev box, I see all the public repositories but none of the user's private ones. 但即使我在开发框中设置了所有范围选项,我也看到了所有公共存储库,但没有看到用户的私有存储库。 I've also tried removing all of the parameters from the url. 我也尝试从网址中删除所有参数。 So that the request is the following. 所以请求如下。

https://api.github.com/users/username/repos

Which again did not return the user's private repositories. 这又没有返回用户的私有存储库。

I am trying to get the private repositories for the current user. 我正在尝试为当前用户获取私有存储库。 But only the ones owned under their account. 但只有他们帐户下拥有的那些。

You are using the wrong endpoint for this. 您正在使用错误的端点。 You are after the following endpoint instead: 您将改为以下端点:

https://developer.github.com/v3/repos/#list-your-repositories https://developer.github.com/v3/repos/#list-your-repositories

https://api.github.com/user/repos

List repositories that the authenticated user has explicit permission (:read, :write, or :admin) to access. 列出经过身份验证的用户具有显式权限(:read,:write或:admin)以进行访问的存储库。 The authenticated user has explicit permission to access repositories they own, repositories where they are a collaborator, and repositories that they can access through an organization membership. 经过身份验证的用户具有访问他们拥有的存储库的明确权限,他们是协作者的存储库以及可以通过组织成员身份访问的存储库。

I've just tested it and this returns your private repositories. 我刚刚测试了它,这将返回您的私有存储库。

Hope this helps. 希望这可以帮助。

You may have to authorize yourself for permission of listing your private repositories. 您可能必须授权自己获得列出私人存储库的许可。

Get an OAuth Token from the account (or from the OAuth Authorizations API ), then add the token as a GET parameter (in query string ?access_token=OAUTH-TOKEN ) or a HTTP header ( Authorization: token OAUTH-TOKEN ) of your request, you may have permission for your need. 从帐户 (或OAuth授权API )获取OAuth令牌,然后将令牌添加为您的请求的GET参数(在查询字符串?access_token=OAUTH-TOKEN )或HTTP标头( Authorization: token OAUTH-TOKEN ) ,您可能已经获得了您的需要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM