【问题标题】:node github API节点 github API
【发布时间】: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.loging process.env.GITHUB_CLIENT_IDprocess.env.GITHUB_CLIENT_SECRET 以确保它们设置为正确的值?
  • 是的,一切都好;我在我的客户端应用程序中通过 jquery $.get() 使用了相同的凭据并且它工作但我想将它移动到服务器端并且我被卡住了..

标签: node.js github


【解决方案1】:

看起来我应该使用github.getFrom 函数而不是github.get。它现在正在工作。 .get 方法似乎需要不同的身份验证。

【讨论】:

  • 它仍然不起作用..我可以做,但作为普通用户查询。
猜你喜欢
  • 1970-01-01
  • 2021-05-15
  • 2021-02-09
  • 2012-07-05
  • 2016-01-31
  • 2017-08-09
  • 2020-11-05
  • 2014-06-15
  • 1970-01-01
相关资源
最近更新 更多