You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am getting an error each time I call getToken with a valid authCode. Here is the error log printed via the code below:
Error getting tokens: invalid_request
Is there something wrong with the way I am using the APIs? Appreciate any pointers...
varexpress=require('express');varrouter=express.Router();vargoogle=require('googleapis');varurlshortener=google.urlshortener('v1');varOAuth2=google.auth.OAuth2;varplus=google.plus('v1');vargoogleClientInfo={"web": {...}};varoauth2=newOAuth2(googleClientInfo.web.client_id,googleClientInfo.web.client_secret,googleClientInfo.web.redirect_uris);varscopes=['https://www.googleapis.com/auth/plus.me','https://www.googleapis.com/auth/calendar'];google.options({auth: oauth2});// set auth as a global defaultvarauthUrl=oauth2.generateAuthUrl({access_type: 'offline',scope: scopes});/* GET authCode from Google Server */router.get('/',function(req,res){console.log('Redirecting to URL: '+JSON.stringify(authUrl));res.redirect(authUrl);});/* '/successful' is the redirect_uri with authCode query */router.get('/successful',function(req,res){console.log('Got code: ',(req.query.code));oauth2.getToken(req.query.code,function(err,tokens){if(err){console.log("Error getting tokens: ",err);res.redirect('/');}else{console.log("Saving tokens: ",JSON.stringify(tokens));// Save tokensoauth2.setCredentials(tokens);plus.people.get({userId: 'me',auth: oauth2},function(err,response){if(err){console.log("Error getting userId: ",err);res.redirect('/');}else{res.send('Login Successful: '+JSON.stringify(response));console.log('Login Successful: '+JSON.stringify(response));}});}});});module.exports=router;
The text was updated successfully, but these errors were encountered:
What is the contents of googleClientInfo.web.redirect_uris ? Is it a string? If it's an Array, try specifying the first value in the array instead like googleClientInfo.web.redirect_uris[0]. If you're getting a valid authCode then I'm not sure if that would matter.
Yes that works! Do you think its a good idea to throw an error if URI is an array? Would save debug time for a poor soul like me :). Thanks much for your help. Cheers.
I am getting an error each time I call getToken with a valid authCode. Here is the error log printed via the code below:
Is there something wrong with the way I am using the APIs? Appreciate any pointers...
The text was updated successfully, but these errors were encountered: