2013-06-06 28 views
0

因此,我正在嘗試向github發出一個HTTP請求,以返回特定github存儲庫上所有問題的列表。我在下面的代碼中使用了coffeescript,但對於任何JS開發人員來說,這應該是相當自我解釋的。我的困惑是,如果我在瀏覽器中輸入「https://api.github.com/repos/username/repo-name/issues」,我可以檢索所有我正在查找的信息。當我嘗試通過我的應用程序通過request node library發出請求時,我收到一條錯誤,指出「Missing or invalid User Agent string」。如果您知道如何正確地構建URL以實際從github API檢索信息,請讓我知道。什麼是用戶代理字符串(github api)

githubUrl = "https://api.github.com/repos/#{username}/#{repoName}/issues?state=open" 

    request githubUrl, (error, response, body) -> 

     console.log body 

回答

5

您需要通過用戶代理字符串像它說:)我剛剛扳回一從鉻:

require('https') 
    .get({ 
     hostname : 'api.github.com' 
     , path :'/repos/cwolves/jquery-imask/issues' 
     , headers : { 
      'User-Agent' : 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1521.3 Safari/537.36' 
     } 
    }, function(res){ 
     res.on('data',function(data){ 
      console.log(data+''); 
    }); 
}); 
相關問題