2014-09-01 81 views
1

我正在尝试编写客户端Javascript分叉给定GitHub回购。我正在使用OAuth.io服务获取API范围设置为“public_repo”和“repo”的OAuth令牌。使用客户端JavaScript和OAuth.io与GitHub API分拣回购

我使用github.js访问GitHub的API,使用fork方法(在makeWebsite功能):

$(document).ready(function() { 
    initializeOAuth(); 
    setEventListener(); 
}); 

var setEventListener = function() { 
    $("#button").click(popupOAuth); 
}; 

var initializeOAuth = function() { 
    OAuth.initialize("rG-ChpeD0zdiIPoJpK58gN4qMJQ"); 
}; 

var popupOAuth = function() { 
    OAuth.popup("github").done(makeWebsite); 
}; 

var makeWebsite = function(result) { 
    var token = result["token"]; 

    var github = new Github({ 
    token: token, 
    auth: "oauth" 
    }); 

    var repo = github.getRepo("michael", "github"); 
    repo.fork(function(err) { 
    console.log(err); 
    }); 
}; 

当我运行这段代码并完成OAuth的舞蹈,我得到以下错误:

404 Not Found

+0

是否*任何* GitHub API调用适合您?任何破坏性的API调用? – Konklone 2014-09-01 15:50:35

+0

是的。 'repo.show(function(err,myRepo){console.log(myRepo);});'把我所有的[this](https://gist.github.com/adelevie/6dcf1b03ccfb0d407d00)。这让我觉得有一个范围问题。 – user94154 2014-09-01 15:53:45

回答

0
var makeWebsite = function(ghClient) { 
    ghClient.post("/repos/MyInternetWebsite/template/forks").done(cb); 
}; 

貌似问题是与github.js。原来,OAuth.io提供了简单的http访问来处理身份验证。对于它的价值,所有需要分叉的是public_repo范围。