2014-10-29 49 views
2

正如標題所說,我正在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倉庫中所有文件的名稱

所以此工程:

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方法。如果任何人都可以弄清楚我的錯誤是什麼(或者可能提出了一個不同的方式來從流星的回購中獲取文件名),我將非常感謝幫助。

編輯:我試過指定一個路徑(即使這是一個可選的參數),我得到了一個稍微不同的結果。

修改後的代碼:

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

回答

2

我試過你的代碼,我得到的文件內容回購

enter image description here

from this issue https://github.com/mikedeboer/node-github/issues/137我有s等路徑emprty

我的代碼

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

謝謝,這似乎是工作!那麼是不同的「Async.runSync」調用呢?我對javascript/web開發很陌生(剛剛開始)。 – 2014-10-29 20:57:16

+0

沒有所有的服務器端API調用在流星中是異步的,通過將代碼包裝在「Async.runSync」中,該方法將等待「完成」方法調用(當我們得到響應時我們調用done方法),並且我們發送響應給te同步調用方法 – Sasikanth 2014-10-30 05:57:06

+0

由於Async.runSync方法,此代碼不起作用 – Sasikanth 2014-10-30 05:57:34

相關問題