[英]Accessing github repository using nodejs
我想使用node中的github api访问github仓库。
var https = require("https");
var userName='sacdh22';
var options = {
host :"api.github.com",
path: "/users/" +userName+ "/repos",
method : 'GET',
headers: {'User-Agent':'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)'}
}
var request = https.request(options, function(response){
var body = '';
response.on('data',function(chunk){
body+=chunk;
});
response.on('end',function(){
var json = JSON.parse(body);
var repos =[];
console.log(json);
//json.forEach(function(repo){
// repos.push({
// name : repo.name,
// description : repo.description
// });
//});
console.log('the repos are '+ JSON.stringify(repos));
});
});
request.on('error', function(e) {
console.error('and the error is '+e);
});
request.end();
当我console.log(body)我得到以下输出。
{"message":"Not Found","documentation_url":"https://developer.github.com/v3"}
{ message: 'Not Found',
documentation_url: 'https://developer.github.com/v3' }
谁能告诉我这里出了什么问题,我猜是路径设置不正确,那么我该如何设置呢?
sacdh22
不是Github上的用户名。 当您尝试访问其存储库列表时,Github会显示“未找到”错误。 将用户名更改为真实的用户名,您将获得截然不同的结果 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.