如何通过GitHub API列出组织的私有存储库?

时间:2013-06-06 12:20:48

标签: github github-api github-organizations

我正在尝试获取组织的所有存储库列表,包括私有存储库。 (或者更具体地说,某个用户可以访问的所有私有存储库。)

要求组织的信息(https://api.github.com/orgs/acme?access_token=[...])表明确实存在大量私有存储库:

...
"public_repos": 5,
"total_private_repos": 68, 
"owned_private_repos": 68, 
...

(我以前使用的访问令牌generated using the API用于username / passwd。)

但无论我试图列出回购......

https://api.github.com/orgs/acme/repos&access_token=[...]   

... GitHub API只返回5个公共存储库。 (Documentation says type=all是默认值。也尝试添加参数type=private;没有区别。)

知道我做错了吗?

实际上生成访问令牌的用户具有Push&只能访问组织的一些私有存储库,但这些都不会出现在我获得的列表中(只有5个公共存储库)。

5 个答案:

答案 0 :(得分:18)

你正在做的一切都很好。但是,在创建OAuth令牌进行身份验证时,请确保您正在定义正确的scopes。每个范围都定义了一组特定的允许操作(您可以读/写的信息),因此您应该检查是否正在创建具有repo范围的令牌。

答案 1 :(得分:2)

# Get Github Repo Names

"""
>>>> pip install PyGithub
>>>> Reference Link: https://pypi.org/project/PyGithub/
>>>> Getting the access token.
        Go to github <settings>.
        Go to <Developer Settings>.
        Go to <Personal access tokens>.
        Click on <Generate new token> button.
        Add a note.
        Check all the setting in that page.
        Click on <Generate token> button.
        Copy  the access token and paste in below code.

>>>>
>>>>
>>>>
>>>>
"""

from github import Github

access_token = ''
g = Github(access_token)
repo_list = [i for i in g.get_user().get_repos()]
for i in repo_list:
    repo_name = str(i).replace('Repository(full_name="', '')
    repo_name = str(repo_name).replace('")', '')
    print('https://www.github.com/' + repo_name)

答案 2 :(得分:0)

还应注意,如果您要从组织访问私有存储库,则根据设置,所有者需要对OAuth应用程序进行授权。

https://help.github.com/articles/authorizing-oauth-apps/

  

对于具有OAuth App访问限制的组织,您可以请求组织管理员批准该应用程序在该组织中使用。如果该组织未批准该应用程序,则该应用程序将只能访问组织的公共资源。如果您是组织管理员,则可以自己批准该应用程序。

     

对于没有OAuth应用访问权限限制的组织,该应用将自动被授权访问该组织的资源。因此,您应注意批准使用哪些OAuth应用访问您的个人信息帐户资源以及任何组织资源。

答案 3 :(得分:0)

您的网址需要一个?不是&。应该是这样:

https://api.github.com/orgs/acme/repos?access_token=your_access_token

答案 4 :(得分:0)

username = "Your_org"
token = "your_TOKEN"
request = requests.get('https://api.github.com/orgs/'+username+'/repos?per_page=1000', auth=(username, token))
相关问题