Search code examples
javascriptnode.jsgoogle-oauth

How to discover APIs in Google OAuth2 in Node.js


I've got a problem with .discover method in Node.js. I've got such a piece of code:

googleapis.discover('oauth2', 'v2').execute(function(err, client){
    if(!err)
        callback(client);
});

And it throws error: TypeError: Object # has no method 'discover' But in all tutorials there is such a method mentioned. Does anyone know what's wrong?


Solution

  • I got the same error. I think they updated the googleapis client for Node.

    Try follow the new syntax or use older version:

    var google = require('googleapis');
    var OAuth2 = google.auth.OAuth2;
    var oauth2Client = new OAuth2(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL);
    var drive = google.drive({ version: 'v2', auth: oauth2Client });