Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

269
Visualizações
Google cloud function, how to set the keyFile path and avoid error?

I have created a cloud function that uses the Gmail API to send me an email. The cloud function is triggered by a google cloud scheduler. When I test this locally, it seems to work but when I upload my function to the Google cloud function code editor and upload it, there is an error in the logs. Note that the function seems to deploy fine and is active.

This is the error from the logs:

enter image description here

I am not sure what keyFile it is refering to or how to set it. This is my code:

/**
 * Triggered from a message on a Cloud Pub/Sub topic.
 *
 * @param {!Object} event Event payload.
 * @param {!Object} context Metadata for the event.
 */


 const {google} = require('googleapis');
 const {authenticate} = require('@google-cloud/local-auth');
 
 const gmail = google.gmail('v1');
 
 const sendMail = async () => {
   // Obtain user credentials to use for the request
   const auth = await authenticate(
     process.env.client_id,
     process.env.client_secret,
     [
       'https://mail.google.com/',
       'https://www.googleapis.com/auth/gmail.compose',
       'https://www.googleapis.com/auth/gmail.send',
     ],
   );
   google.options({auth});
 
   // You can use UTF-8 encoding for the subject using the method below.
   // You can also just use a plain string if you don't need anything fancy.
   const subject = '🤘 Hello 🤘';
   const utf8Subject = `=?utf-8?B?${Buffer.from(subject).toString('base64')}?=`;
   const messageParts = [
     'From: Oamar Kanji <oamarkanji@gmail.com',
     'To: Oamar Kanji <oamarkanji@gmail.com>',
     'Content-Type: text/html; charset=utf-8',
     'MIME-Version: 1.0',
     `Subject: ${utf8Subject}`,
     '',
     'This is a message just to say hello.',
     'So... <b>Hello!</b>  🤘❤️😎',
   ];
   const message = messageParts.join('\n');
 
   // The body needs to be base64url encoded.
   const encodedMessage = Buffer.from(message)
     .toString('base64')
     .replace(/\+/g, '-')
     .replace(/\//g, '_')
     .replace(/=+$/, '');
 
   const res = await gmail.users.messages.send({
     userId: 'me',
     requestBody: {
       raw: encodedMessage,
     },
   });
   console.log(res.data);
   return res.data;
 }
 
 exports.alertPubSub = async (event, context) => {
 
    await sendMail()

 };
 
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda