简体   繁体   中英

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. I need to use the GitHub API to get data from the private repositories. I am using the following python code:

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. 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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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