I try to collect the collaborators of some project, but the website send the message "Requires authentication ". Could you explain how to user your system to complete it? Thanks for your help.
Hi @Nightrord , thank you for your interest in this project.
The following code gets a list of collaborators for a repository:
from github import Github
# Generate a token at https://github.com/settings/tokens
token = 'XXX'
g = Github(token)
repo_name = 'adamtheturtle/github-experiment'
repo = g.get_repo(repo_name)
collaborators = repo.get_collaborators()
for collaborator in collaborators:
print collaborator.login
Please let me know whether this helps.
Adam
Hi @adamtheturtle , a question. It's possible to obtain collaborator list without passing 'token' param?
@dmiro Yes you can pass a username and password to authenticate as well.
https://github.com/PyGithub/PyGithub/blob/master/github/MainClass.py#L57
I don't understand because authentication is mandatory in a public repository if only want retrieve the collaborator list :-/ .... collaborator list it's a public data
@dmiro Apologies for my limited knowledge on this but it seems that getting the collaborators via GitHub's API requires authentication for this.
(playground) Adam@Adam-Dangoor ~/D/scratch> curl https://api.github.com/repos/adamtheturtle/github-experiment/collaborators
{
"message": "Requires authentication",
"documentation_url": "https://developer.github.com/v3"
}
(playground) Adam@Adam-Dangoor ~/D/scratch> curl --user "adamtheturtle:$TOKEN" https://api.github.com/repos/adamtheturtle/github-experiment/collaborators
[
{
"login": "adamtheturtle",
"id": 797801,
"avatar_url": "https://avatars.githubusercontent.com/u/797801?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/adamtheturtle",
"html_url": "https://github.com/adamtheturtle",
"followers_url": "https://api.github.com/users/adamtheturtle/followers",
"following_url": "https://api.github.com/users/adamtheturtle/following{/other_user}",
"gists_url": "https://api.github.com/users/adamtheturtle/gists{/gist_id}",
"starred_url": "https://api.github.com/users/adamtheturtle/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/adamtheturtle/subscriptions",
"organizations_url": "https://api.github.com/users/adamtheturtle/orgs",
"repos_url": "https://api.github.com/users/adamtheturtle/repos",
"events_url": "https://api.github.com/users/adamtheturtle/events{/privacy}",
"received_events_url": "https://api.github.com/users/adamtheturtle/received_events",
"type": "User",
"site_admin": false,
"permissions": {
"admin": true,
"push": true,
"pull": true
}
},
{
"login": "davidoliverSP2",
"id": 12032446,
"avatar_url": "https://avatars.githubusercontent.com/u/12032446?v=3",
"gravatar_id": "",
"url": "https://api.github.com/users/davidoliverSP2",
"html_url": "https://github.com/davidoliverSP2",
"followers_url": "https://api.github.com/users/davidoliverSP2/followers",
"following_url": "https://api.github.com/users/davidoliverSP2/following{/other_user}",
"gists_url": "https://api.github.com/users/davidoliverSP2/gists{/gist_id}",
"starred_url": "https://api.github.com/users/davidoliverSP2/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/davidoliverSP2/subscriptions",
"organizations_url": "https://api.github.com/users/davidoliverSP2/orgs",
"repos_url": "https://api.github.com/users/davidoliverSP2/repos",
"events_url": "https://api.github.com/users/davidoliverSP2/events{/privacy}",
"received_events_url": "https://api.github.com/users/davidoliverSP2/received_events",
"type": "User",
"site_admin": false,
"permissions": {
"admin": false,
"push": true,
"pull": true
}
}
]
Thanks for the clarification. It mean than github API impose a limitation.
You've hunted the guilty ;-))
Hi , Thank you all.
but can you explain how can I print the collaborator ?
I am getting error on these two lines:
"
for collaborator in collaborators:
print (collaborator.login)
"
A python 3 version (not much change). Keep in mind you must have push access to view a given repository collaborators.
#!/usr/bin/env python3
from github import Github
# Generate a token at https://github.com/settings/tokens
token = 'XXX'
g = Github(token)
repo_name = 'bitcoin/bitcoin'
repo = g.get_repo(repo_name)
collaborators = repo.get_collaborators()
for collaborator in collaborators:
print(collaborator.login)
Most helpful comment
@dmiro Apologies for my limited knowledge on this but it seems that getting the collaborators via GitHub's API requires authentication for this.