Github的Web API授权问题 – 返回“未find”

由于我没有发现任何人有同样的问题,我希望这是一件简单的事情。 我相当新鲜。

这是一个Node / Express应用程序,我正尝试连接到Githubs Web API并检索某个特定回购的问题。 我已经生成了一个个人令牌,并将其与基本授权一起使用。 当我尝试连接时,我得到:“ 未find ”。 Github的状态,authentication是必要的,他们返回404/403,我得到404,所以它必须与身份validation。 回购有问题。

令牌不应该有问题,我select“回购”作为访问范围。

其实我不知道我在做什么HTTP请求,但我已经尝试了请求和http。 所以除了别的以外,我想知道是否是授权标题是错误的。

我粘贴我现在使用请求的代码,并返回正文。 任何帮助是极大的赞赏。

const githubToken = process.env.TOKEN; let options = { url: "https://api.github.com/repos/myOrg/myRepo/issues/", headers: { "Authorization": "Basic " + githubToken, "User-Agent": "Mozilla/5.0", "Content-Type": "application/json" } }; let requestCB = function(error, response, body) { if (error) { console.log(error); } else if (!error && response.statusCode == 200) { let info = JSON.parse(body); console.log("Success"); console.log(info); } else { console.log(response); console.log(body); } }; request(options, requestCB); 

而响应的结束和正文:

  read: [Function], body: '{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}' } {"message":"Not Found","documentation_url":"https://developer.github.com/v3"} 

编辑:

所以我find了帮助,在下面发布解决scheme。 我想问题是必须包含accept-header。 也许主机名,path和uri也必须采用这种格式。

 let options = { headers: { "User-Agent": "GitHub-username", "Accept": "application/vnd.github.v3+json", "Authorization": "token " + githubToken }, hostname: "api.github.com", path: "/repos/org/repo/issues", uri: "https://api.github.com/repos/org/repo/issues", method: "GET" }; 

基本authentication不需要令牌

基本authentication

 curl -u "username" https://api.github.com 

所以在你的请求中,你可以省略githubToken

有关authenticationtypes的更多信息,请参阅文档

使用令牌

 var request = require('request'); var options = { url: 'https://api.github.com/?access_token=OAUTH-TOKEN', headers: { "Authorization": "token ", "User-Agent": "Mozilla/5.0", "Content-Type": "application/json" } }; function callback(error, response, body) { if (!error && response.statusCode == 200) { console.log(body); } } 

请求(选项,callback);