I am trying to use a personal access token for accessing the contents of a repository.
If the repository is public I can achieve this both with v3 and with v4 api. Both of the requests below return the contents:
v3:
curl https://api.github.com/repos/w3c/webappsec/contents/
v4:
query {
repository(owner: "w3c", name: "webappsec") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
Now I have generated a personal access token for performing this operation in one of my private repositories, but it never returns anything:
v3 (with Authorization token):
curl -H "Authorization: bearer myauthorizationtoken" https://api.github.com/repos/myusername/myrepo/contents/
Result:
{
"message": "Not Found",
"documentation_url": "https://developer.github.com/v3/repos/contents/#get-contents"
}
v4 (with Authorization token):
query {
repository(owner: "myusername", name: "myrepo") {
object(expression: "master:") {
... on Tree {
entries{
name
}
}
}
}
}
result:
{
"data": {
"repository": {
"object": null
}
}
}
I've tried checking all read
checkboxes while generating the token but nothing. What am I doing wrong?
Looks like, to obtain this information, all repo
access rights for the token are required.
Works for me:
[x] repo Full control of private repositories
[x] repo:status Access commit status
[x] repo_deployment Access deployment status
[x] public_repo Access public repositories
[x] repo:invite Access repository invitations
Rights checkboxes
API v3 usage:
$ curl -H "Authorization: bearer $private_token" https://api.github.com/repos/dmytrohoi/site.source/contents/
[
{
"name": ".github",
"path": ".github",
"sha": "hash",
"size": 0,
"url": "https://api.github.com/repos/dmytrohoi/site.source/contents/.github?ref=master",
"html_url": "https://github.com/dmytrohoi/site.source/tree/master/.github",
"git_url": "https://api.github.com/repos/dmytrohoi/site.source/git/trees/hash",
"download_url": null,
"type": "dir",
"_links": {
"self": "https://api.github.com/repos/dmytrohoi/site.source/contents/.github?ref=master",
"git": "https://api.github.com/repos/dmytrohoi/site.source/git/trees/hash",
"html": "https://github.com/dmytrohoi/site.source/tree/master/.github"
}
},
...
]