app/fetch-data/googleAuthorize.js
/**
 * Create an OAuth2 client with the given credentials, and then execute the
 * given callback function.
 *
 * @param {Object} credentials The authorization client credentials.
 * @param {function} callback The callback to call with the authorized client.
 */
Create an OAuth2 client with the given credentials, and then execute the
given callback function.

@param {Object} credentials The authorization client credentials.
@param {function} callback The callback to call with the authorized client.
Create an OAuth2 client with the given credentials and then execute the given callback function . @param { Object } credentials The authorization client credentials . @param { function } callback The callback to call with the authorized client .
function authorize(credentials) {
  return new Promise((resolve)=> {
    var clientSecret = credentials.installed.client_secret;
    var clientId = credentials.installed.client_id;
    var redirectUrl = credentials.installed.redirect_uris[0];
    var auth = new googleAuth();
    var oauth2Client = new auth.OAuth2(clientId, clientSecret, redirectUrl);
    fs.readFile(TOKEN_PATH, function(err, token) {
      if (err) {
        getNewToken(oauth2Client)
          .then((auth)=>{
            resolve(auth);
          });
      } else {
        oauth2Client.credentials = JSON.parse(token);
        resolve(oauth2Client);
      }
    });
  });
}
function authorize ( credentials ) { return new Promise ( ( resolve ) => { var clientSecret = credentials . installed . client_secret ; var clientId = credentials . installed . client_id ; var redirectUrl = credentials . installed . redirect_uris [ 0 ] ; var auth = new googleAuth ( ) ; var oauth2Client = new auth . OAuth2 ( clientId , clientSecret , redirectUrl ) ; fs . readFile ( TOKEN_PATH , function ( err , token ) { if ( err ) { getNewToken ( oauth2Client ) . then ( ( auth ) => { resolve ( auth ) ; } ) ; } else { oauth2Client . credentials = JSON . parse ( token ) ; resolve ( oauth2Client ) ; } } ) ; } ) ; }
Create an OAuth2 client with the given credentials, and then execute the
 given callback function.
Create an OAuth2 client with the given credentials and then execute the given callback function .
// Check if we have previously stored a token.