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

标签 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"}}

最佳答案

我已经尝试过您的代码,并且正在获取存储库的文件内容

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;
    },

关于javascript - 使用 Meteor 访问 github 存储库中所有文件的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26638617/

相关文章:

javascript - Meteor - createContainer 未渲染到 React

javascript - Jest/ react - TypeError : Cannot read property 'touchStart' of undefined

javascript - angularjs和requirejs中 "Q"和 "q"之间的区别

javascript - Jquery 不从 JSON 文件读取

node.js - 如何优雅地关闭 mongoose 的连接池?

node.js - simple-peer 包无法按预期工作

javascript - 滚动时堆叠 div

javascript - Angular - 选择时出错 - NgFor 仅支持绑定(bind)到 Iterables,例如数组

javascript - POST 请求仅在服务器启动后第二次有效

mongodb - Meteor.Collection 和 Meteor.Collection.Cursor