简体   繁体   English

使用Node.js访问github存储库

[英]Accessing github repository using nodejs

I wanted to access github repositories using github api in node.` 我想使用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();

When i console.log(body) I get the following output. 当我console.log(body)我得到以下输出。

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

Can any one tell me what is going wrong here, my guess is that the path is not set properly, so how can I set it? 谁能告诉我这里出了什么问题,我猜是路径设置不正确,那么我该如何设置呢?

sacdh22 is not a username on Github. sacdh22不是Github上的用户名。 When you try to access a list of their repositories, Github gives you a Not Found error. 当您尝试访问其存储库列表时,Github会显示“未找到”错误。 Change the username to a real one and you will get very different results . 将用户名更改为真实的用户名,您将获得截然不同的结果

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

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