0
votes

I tried to hit my git hub API to get some data. I have my Client ID and Client Secret. Code which I tried put is below:

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']
  }
});

and

hitting API with :

    loadUserFromServer2 : function (username){
      github.user.get({
        user: username,
      },function(err,res){
        if(err){
          console.log(err);
        }
        console.log(JSON.stringify(res));
      });
    }

I am getting the error that (..)

{ [Error: {"message":"Requires authentication","documentation_url":"https://developer.github.com/v3"}] [error] (..), code: 401 }

What am I missing in my authorization ?

It still does not work. I was able to have the access as a normal user.

My code is :

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']
  }
});

But I am still getting below reply:

{ [Error: {"message":"Requires authentication","documentation_url":"https://developer.github.com/v3/oauth_authorizations/#oauth-authorizations-api"}]

1
Have you tried console.loging process.env.GITHUB_CLIENT_ID and process.env.GITHUB_CLIENT_SECRET to ensure that they are set to the proper values? - Travis Kaufman
yes, all good ; I used same credentials via jquery $.get() in my client app and it worked but I wanted to move it to the server side and i am stuck .. - marcinwal

1 Answers

0
votes

It looks like I should have used github.getFrom function instead of github.get. It is working now. It seems like different authentication is needed for .get method.