【发布时间】:2015-07-28 14:44:17
【问题描述】:
我试图点击我的 git hub API 来获取一些数据。 我有我的客户 ID 和客户密码。 我试过的代码如下:
var GitHubApi = require('github');
var github = new GitHubApi({
version: "3.0.0",
debug: true,
protocol: "https",
host: "api.github.com",
timeout: 5000,
authenticate: {
type: "oauth",
key: process.env['GITHUB_CLIENT_ID'],
secret: process.env['GITHUB_CLIENT_SECRET']
}
});
和
hitting API with :
loadUserFromServer2 : function (username){
github.user.get({
user: username,
},function(err,res){
if(err){
console.log(err);
}
console.log(JSON.stringify(res));
});
}
我得到的错误是 (..)
{ [错误:{“消息”:“需要身份验证”,“documentation_url”:“https://developer.github.com/v3”}] [错误] (..), 代码:401 }
我的授权中缺少什么?
还是不行。我能够以普通用户的身份访问。
我的代码是:
github.authorization.create({
"scopes" : ["user"],
"note" : "admin server rights",
"type" : "oauth",
"app": {
"name" : "gitHubNetwork",
"client_id" : process.env['GITHUB_CLIENT_ID'],
"client_secret" : process.env['GITHUB_CLIENT_SECRET']
}
});
但我仍然收到以下回复:
{ [错误:{"message":"Requires authentication","documentation_url":"https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api"}]
【问题讨论】:
-
您是否尝试过
console.logingprocess.env.GITHUB_CLIENT_ID和process.env.GITHUB_CLIENT_SECRET以确保它们设置为正确的值? -
是的,一切都好;我在我的客户端应用程序中通过 jquery $.get() 使用了相同的凭据并且它工作但我想将它移动到服务器端并且我被卡住了..