繁体   English   中英

如何通过 GitHub API 访问私有仓库?

[英]How to access Private Repository through GitHub API?

根据文档,我可以访问这样的公共存储库:

GET /repos/:owner/:repo

但是如何访问私有仓库?

我创建了一个令牌,它可以访问我的所有存储库并将其添加到标题中,但问题仍然存在。

我的代码:

const https = require('https');
const oAuth = require('oauth');

const owner = '<owner>';
const repo = '<repo>';
let data = '';

const options = {
  host: 'api.github.com',
  path: '/repos/' + owner + '/' + repo,
  method: 'GET',
  headers: { 

    'user-agent': '<myGitHubAccount>',
    'authorization': 'token <token>'

  }
};

const request = https.request(options, function (response) {
  var body = '';
  response.on("data", function (chunk) {
    body += chunk.toString('utf8');
  });

  response.on("end", function () {
    console.log(body);
  });
});

request.end();

安慰:

{"message":"Not Found","documentation_url":"https://developer.github.com/v3/repos/#get"}

提前致谢。

首先检查所使用的令牌是否是具有正确范围OAuth 令牌

例如,范围“ repo ”,它授予对私有和公共存储库的完全访问权限。

暂无
暂无

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

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