async function runSample() {
  // Obtain user credentials to use for the request
  const auth = await authenticate({
    keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
    scopes: [
      'https://mail.google.com/',
      'https://www.googleapis.com/auth/gmail.metadata',
      'https://www.googleapis.com/auth/gmail.modify',
      'https://www.googleapis.com/auth/gmail.readonly',
    ],
  });
  google.options({auth});

  const res = await gmail.users.watch({
    userId: 'me',
    requestBody: {
      // Replace with `projects/${PROJECT_ID}/topics/${TOPIC_NAME}`
      topicName: 'projects/el-gato/topics/gmail',
    },
  });
  console.log(res.data);
  return res.data;
}
/**
 * NOTE: Before using this API, you need to do a few things.
 * 1. Create a new Pub/Sub topic.  You can use the command:
 *      gcloud pubsub topics create gmail
 * 2. Go to the Cloud Developer Console, and give the gmail
 *    service account gmail-api-push@system.gserviceaccount.com
 *    Pub/Sub Publisher rights to your newly created topic.
 *    https://console.cloud.google.com/cloudpubsub/topicList?project=${PROJECT_NAME}
 */
Before using this API, you need to do a few things.
1. Create a new Pub/Sub topic.  You can use the command:
gcloud pubsub topics create gmail
2. Go to the Cloud Developer Console, and give the gmail
service account gmail-api-push@system.gserviceaccount.com
Pub/Sub Publisher rights to your newly created topic.
Before using this API you need to do a few things . 1 . Create a new Pub / Sub topic . You can use the command : gcloud pubsub topics create gmail 2 . Go to the Cloud Developer Console and give the gmail service account gmail - api - push@system . gserviceaccount . com Pub / Sub Publisher rights to your newly created topic .
async function runSample() {
  const auth = await authenticate({
    keyfilePath: path.join(__dirname, '../oauth2.keys.json'),
    scopes: [
      'https://mail.google.com/',
      'https://www.googleapis.com/auth/gmail.metadata',
      'https://www.googleapis.com/auth/gmail.modify',
      'https://www.googleapis.com/auth/gmail.readonly',
    ],
  });
  google.options({auth});
  const res = await gmail.users.watch({
    userId: 'me',
    requestBody: {
      topicName: 'projects/el-gato/topics/gmail',
    },
  });
  console.log(res.data);
  return res.data;
}
async function runSample ( ) { const auth = await authenticate ( { keyfilePath : path . join ( __dirname , '../oauth2.keys.json' ) , scopes : [ 'https://mail.google.com/' , 'https://www.googleapis.com/auth/gmail.metadata' , 'https://www.googleapis.com/auth/gmail.modify' , 'https://www.googleapis.com/auth/gmail.readonly' , ] , } ) ; google . options ( { auth } ) ; const res = await gmail . users . watch ( { userId : 'me' , requestBody : { topicName : 'projects/el-gato/topics/gmail' , } , } ) ; console . log ( res . data ) ; return res . data ; }
NOTE: Before using this API, you need to do a few things.
NOTE : Before using this API you need to do a few things .
// Obtain user credentials to use for the request // Replace with `projects/${PROJECT_ID}/topics/${TOPIC_NAME}`