简体   繁体   English

如何使用 GitHub API 提取私有仓库数据?

[英]How can I pull private repo data using GitHub API?

I am a member of an organization which has a lot of private repositories on GitHub.我是一个组织的成员,该组织在 GitHub 上有很多私有存储库。 I need to use the GitHub API to get data from the private repositories.我需要使用 GitHub API 从私有存储库中获取数据。 I am using the following python code:我正在使用以下 python 代码:

url = "https://api.github.com/orgs/myorg/repos?access_token=[mytokenhere]"
headers = {"Authorization": "token [myPATHhere]"}
session = requests.Session()
response = session.get(url, headers = headers)
content = response.text

my_json = json.loads(response.text)


for item in my_json:
    print(item['html_url'])

Where PAT = my access token.其中 PAT = 我的访问令牌。 This still only returns the public repositories.这仍然只返回公共存储库。 I've seen the related question but the listed solutions do not solve my problem.我看过相关的问题,但列出的解决方案并没有解决我的问题。 Note that I've authorized my access token to get into the private repository.请注意,我已授权我的访问令牌进入私有存储库。 I've also tried api.github.com/users/repos and api.github.com/users/[myorghere] and still no private repos are returned.我也试过 api.github.com/users/repos 和 api.github.com/users/[myorghere] 并且仍然没有返回私人回购。 Am I not submitted the token correctly?我没有正确提交令牌吗?

Go into your personal access token and ensure that you have selected the necessary scopes.进入您的个人访问令牌并确保您选择了必要的范围。 The first one is for private repos so you may need to select some/all of the options there.第一个用于私人回购,因此您可能需要在那里选择部分/全部选项。

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

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