Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

nodejs googleapis, authClient.request is not a function

I am creating an oauth2client in one function like so and returning it. I actually do pass in the clien id, secret, redirect url, and credentials. Those are all correct from what I have checked.

var OAuth2 = google.auth.OAuth2;
var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
...
credentials = {
      access_token: accessToken,
      refresh_token: refreshToken
};
oauth2Client.setCredentials(credentials);

I then do this in the function where the oauth2client object is returned:

var plus = google.plus('v1');
console.log(JSON.stringify(oauth_client));
plus.people.get({ userId: 'me' , auth: oauth_client}, function(err, response) {
    if(err) {
        console.log(err);
    } else {
        console.log(JSON.stringify(response));
        return response;
    }
});

However I then get an error message saying that authClient.request is not a function.

TypeError: authClient.request is not a function at createAPIRequest (/node_modules/googleapis/lib/apirequest.js:180:22)

I'm not sure why I get this error. I also did console.log(JSON.stringify(oauth_client)) to check for a request function and I didn't see any. Someone mentioned that this can't display the full prototype chain and that the request function might actually be there.

like image 978
EthanLWillis Avatar asked Sep 21 '16 16:09

EthanLWillis


1 Answers

The problem is with "oauth_client".I used "google-auth-library" to authenticate.

var googleAuth = require('google-auth-library');
var auth = new googleAuth();
var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
oauth2Client.credentials = credentials;

and then use this oauth2Client as oauth_client.

like image 159
sandeep rajbhandari Avatar answered Nov 07 '22 12:11

sandeep rajbhandari