title: nodejs - connect with gmail-api
body: <p>I want to let users to connect to my <code>node.js server</code> with their <code>gmail</code>. I have created a project in the <code>Google Developers Console</code>. Then use the following code:</p>
  
  <pre><code>const express = require('express');
  const google = require('googleapis');
  const googleAuth = require('google-auth-library');
  
  const credentials = require('../link/of/some/file.json'); // google credential
  
  let clientSecret = credentials.web.client_secret;
  let clientId = credentials.web.client_id;
  let redirectUrl = credentials.web.redirect_uris[0];
  
  const SCOPES = [
     'https://mail.google.com/',
     'https://www.googleapis.com/auth/gmail.modify',
     'https://www.googleapis.com/auth/gmail.readonly'
  ];
  
  let auth = new googleAuth();
  let oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
  
  app.get('/connect', (req, res) =&gt; {
     let authUrl = oauth2Client.generateAuthUrl({
        access_type: 'offline',
        scope: SCOPES
     });
     res.redirect(authUrl);
  });
  </code></pre>
  
  <p>when <code>/connect</code> is called, it will redirect to google page to verify user.   After user give access of his/her account, google will automatically call the following api with a <code>code</code> query parameter:</p>
  
  <pre><code>app.get('/auth/callback', (req, res) =&gt; {
      // 'req.query.code' is provided by google
      return oauth2Client.getToken(req.query.code, (err, token) =&gt; {
         // token value:
         /*
            { 
               access_token: 'ya29.Gls2Ba_rXEA5EoBaFH5bPdDDzgaSWOtb0GSJcnaTP47Jh7HwHdF2ZJZOlQaCJBC5wjpq-sOLBVlIM9L8BMslVyHw22nveU0MwQ4iJPTq5vkjXDeitqtoYH8JO83w',
               refresh_token: '1/S0C3w-8vnqcrGE4Z2mSW9ctYkaitVuZquBSJ0WJJHUs',
               token_type: 'Bearer',
               expiry_date: 1514897380473 
            }
         */
      });
  });
  </code></pre>
  
  <p>Now, My problem is, in the above token value, I cannot understand how can I get gmail address from that token. What am I missing???</p>
  
  <p>Any Suggestion? Thanks in advance. </p>