auth/google-oauth.js
/**
 * OAuthHandler
 *
 * @param {string} code The code return by the google OAuth.
 * @param {OAuth2} oauth2Client The client OAuth instance
 *
 */
OAuthHandler
@param {string} code The code return by the google OAuth.
@param {OAuth2} oauth2Client The client OAuth instance
OAuthHandler @param { string } code The code return by the google OAuth . @param { OAuth2 } oauth2Client The client OAuth instance
function oAuthHandler(code, oauth2Client) {
  oauth2Client.getToken(code, function (err, token) {
    if (err) {
      console.log('Error while trying to retrieve access token', err);
      return;
    }
    oauth2Client.credentials = token;
    storeToken(token);
    const tasksYoutube = async () => {
      console.log(
        'scheduler tasksYoutube running...',
        new Date(Date.now()).toLocaleString()
      );
      try {
        const views = await VIDEO_JOBS.getVideoViews(
          oauth2Client,
          VIDEO_ID,
          google
        );
        const title = await VIDEO_JOBS.updateVideoTitle(
          oauth2Client,
          VIDEO_ID,
          views,
          google
        );
        console.log('New title ' + title);
      } catch (error) {
        console.log('Houve um erro! ', error);
      }
    };
    const tasksTwitter = async () => {
      console.log(
        'scheduler tasksTwitter running...',
        new Date(Date.now()).toLocaleString()
      );
      const usersNames = await TWITTER_HANDLER.getRetweetersInfo();
      try {
        const description = await VIDEO_JOBS.updateVideoDescription(
          oauth2Client,
          VIDEO_ID,
          usersNames,
          google
        );
        console.log('New description ' + description);
      } catch (error) {
        console.log('Houve um erro! ', error);
      }
    };
    tasksYoutube();
    tasksTwitter();
    const scheduleOptions = {
      scheduled: true,
      timezone: 'America/Sao_Paulo',
    };
    cron.schedule('*/3 * * * *', tasksYoutube, scheduleOptions);
    cron.schedule('*/30 * * * *', tasksTwitter, scheduleOptions);
  });
}
function oAuthHandler ( code , oauth2Client ) { oauth2Client . getToken ( code , function ( err , token ) { if ( err ) { console . log ( 'Error while trying to retrieve access token' , err ) ; return ; } oauth2Client . credentials = token ; storeToken ( token ) ; const tasksYoutube = async ( ) => { console . log ( 'scheduler tasksYoutube running...' , new Date ( Date . now ( ) ) . toLocaleString ( ) ) ; try { const views = await VIDEO_JOBS . getVideoViews ( oauth2Client , VIDEO_ID , google ) ; const title = await VIDEO_JOBS . updateVideoTitle ( oauth2Client , VIDEO_ID , views , google ) ; console . log ( 'New title ' + title ) ; } catch ( error ) { console . log ( 'Houve um erro! ' , error ) ; } } ; const tasksTwitter = async ( ) => { console . log ( 'scheduler tasksTwitter running...' , new Date ( Date . now ( ) ) . toLocaleString ( ) ) ; const usersNames = await TWITTER_HANDLER . getRetweetersInfo ( ) ; try { const description = await VIDEO_JOBS . updateVideoDescription ( oauth2Client , VIDEO_ID , usersNames , google ) ; console . log ( 'New description ' + description ) ; } catch ( error ) { console . log ( 'Houve um erro! ' , error ) ; } } ; tasksYoutube ( ) ; tasksTwitter ( ) ; const scheduleOptions = { scheduled : true , timezone : 'America/Sao_Paulo' , } ; cron . schedule ( '*/3 * * * *' , tasksYoutube , scheduleOptions ) ; cron . schedule ( '*/30 * * * *' , tasksTwitter , scheduleOptions ) ; } ) ; }
OAuthHandler
 @param {string} code The code return by the google OAuth.
OAuthHandler @param { string } code The code return by the google OAuth .