Nodejs googleapis, authClient.request is not a function

I create oauth2client in one function, for example, and return it. I really pass the clien id, secret, redirect url and credentials. They are all true from what I 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);

Then I do this in a function that returns an oauth2client object:

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, then I get an error saying that authClient.request is not a function.

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

I am not sure why I am getting this error. I also did console.log (JSON.stringify (oauth_client)) to check the request function, and I did not see. Someone pointed out that this cannot display the complete prototype chain, and that the query function may indeed be there.

+4
2

"oauth_client". "google-auth-library" .

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

oauth2Client oauth_client.

+2

Source: https://habr.com/ru/post/1655361/


All Articles