2012-10-19 77 views
0

如何在扩展中使用我的github帐户。我的意思是,如何通过我的账户在自己的扩展程序中获得回购列表或其他内容?我发现很多扩展到github,但我无法找到源如何使它..Github在Chrome扩展中

回答

2

这很简单,但我喜欢使用JavaScript包装器,而不是让ajax自己调用。您将需要生成一个oAuth令牌。 Here is a working example

如果您不熟悉oAuth,它基本上是您为您的帐户创建的特殊密码,它允许您的扩展程序访问您的应用程序(GitHub)数据。您可以将此特殊密码的访问权限仅限于防止安全问题所需的信息。

  1. 下载Github.js library
  2. 转到https://github.com/settings/tokens/new REMEBER取消选中所有复选框!这将只允许此密码访问您的github帐户上的公共信息。点击Generate tokenenter image description here
  3. 复制您的访问键下方enter image description here
  4. 使用代码来获得回购列表

Github.js需要Underscore.js

//get access to account 
var github = new Github({ 
    token: "e7e427e4a8cc0f424a77a0******************", 
    auth: "oauth" 
}); 

//get user 
var user = github.getUser(); 

//get repos 
user.repos(function(err, repos) { 
    //loop through repos 
    for (i = 0; i < repos.length; i++) { 
    repo = repos[i]; 
    //access repo here 
    } 
});