简体   繁体   English

Github 用于访问私有存储库的个人访问令牌:/repos/:user/:repo/contents

[英]Github personal access token for accessing private repository's: /repos/:user/:repo/contents

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.如果存储库是公共的,我可以使用 v3 和 v4 api 来实现这一点。 Both of the requests below return the contents:以下两个请求都返回内容:

v3: v3:

curl https://api.github.com/repos/w3c/webappsec/contents/

v4: 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): v3(带有授权令牌):

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): v4(带有授权令牌):

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.我尝试在生成令牌时检查所有已read复选框,但没有。 What am I doing wrong?我究竟做错了什么?

Looks like, to obtain this information, all repo access rights for the token are required.看起来,要获取此信息,需要令牌的所有repo访问权限。

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: API v3 用法:

$ 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"
    }
  },
...
]

暂无
暂无

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

相关问题 GitHub 个人访问令牌私人回购 scope - GitHub Personal Access Token Private repo scope Github:您可以访问用户使用个人令牌与您共享的私有存储库列表吗? - Github: Can you access the list of private repos that a user has shared with you using the personal token? 从 github 私人仓库安装 package 没有个人访问令牌 - Install package from github private repo without personal access token 使用个人访问令牌 Netbeans 克隆私有 Github 回购 - Clone a Private Github Repo with a Personal Access Token Netbeans 无法在私人仓库中使用个人访问令牌列出仓库 webhook - Cannot list repository webhooks using personal access token in private repo 使用个人访问令牌将 Gradle 上的脚本应用于私有(企业)github 存储库 - Apply Script on Gradle to private (enterprise) github repo using personal access token 今天,github 突然阻止我使用我的个人访问令牌访问我的 repo - Today, github suddenly block me from accessing my repo with my Personal Access Token 如何使用个人访问令牌在 github 操作工作流 (B) 中从不同的存储库 (B) 提交和推送到私有存储库 (A) - How to commit and push to a private repo(A), from a different repo(B), in github actions workflow (B) , using personal access token 无法使用个人访问令牌访问私人 Git 回购 - Can't Access Private Git Repo With Personal Access Token Github使用访问令牌获取私人仓库 - Github GET on private repo with access token
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM