使用Meteor访问github存储库中所有文件的名称

时间:2014-10-29 19:07:29

标签: javascript node.js meteor github-api

正如标题所说,我正在Meteor中编写一个Web应用程序,并试图访问github仓库中所有文件的名称。我有一个Node github api包装器设置(它包装的实际api位于https://github.com/mikedeboer/node-github),我能够成功地进行一些其他github api调用(即github.repos.getAll和gethub.user) .getFollowingFromUser)。但是,出于某种原因,当我尝试使用github.repos.getContent时,无论我以用户名或回购方式传入什么内容,都会收到404错误。

这样可行:

 github.user.getFollowingFromUser(
     {
       user: "ndhoule" 
     },
     function(err, res) {
     console.log(JSON.stringify(res));
     });

但这不是:

 github.repos.getContent(
     {
       user: "ndhoule",
       repo: "meteor-github-api"
     }, 
     function(err, res){console.log(JSON.stringify(res))
   });

这是它产生的错误:

I20141029-13:46:01.875(-5)? [error] { [Error: {"message":"Not    
Found","documentation_url":"https://developer.github.com/v3"}]
I20141029-13:46:01.876(-5)? [error]   message: '{"message":"Not    
Found","documentation_url":"https://developer.github.com/v3"}',
I20141029-13:46:01.877(-5)? [error]   code: 404 } null ndhoule
I20141029-13:46:01.877(-5)? undefined

无论我插入哪个用户名,都会发生这种情况,所以我假设我某种方式错误地使用了getContent方法。如果有人能弄清楚我的错误是什么(或者可能建议采用不同的方式从Meteor的回购中获取文件名),我将非常感谢帮助。

编辑:我尝试指定一个路径(即使这是一个可选的参数),我的结果略有不同。

修订代码:

github.repos.getContent(
     {
       user: "ndhoule",
       repo: "meteor-github-api"
       path: "./"
     }, 
     function(err, res){console.log(JSON.stringify(res))
   });

现在我在控制台中只有这个输出:

{"meta":{"x-ratelimit-limit":"60","x-ratelimit-remaining":"59"}}

1 个答案:

答案 0 :(得分:2)

我已尝试过您的代码,并且我正在为回购获取文件内容

enter image description here

来自这个问题https://github.com/mikedeboer/node-github/issues/137我已经设置了通往

的路径

我的代码

client.js

        Meteor.call("repocontent",uname,repoName,function(e,r){
          console.log(r);
        });

服务器方法中的server.js

 'repocontent':function(uname,repoName){
        var reposcontent=Async.runSync(function(done){
           github.repos.getContent({user:uname,repo:repoName,path: ""},function(err,data){
              done(null,data) ;
           }); 
        });
        return reposcontent;
    },