Google cloud platform gmail users.watch API 400使用域范围委派的错误请求

Google cloud platform gmail users.watch API 400使用域范围委派的错误请求,google-cloud-platform,google-api,google-cloud-functions,gmail-api,google-api-nodejs-client,Google Cloud Platform,Google Api,Google Cloud Functions,Gmail Api,Google Api Nodejs Client,调用users.watch Gmail API时收到400个错误请求,请从GCP Cloud函数 我正在尝试在用户GSuite电子邮件帐户上自动调用watch()。我已经按照下面链接中概述的步骤,在整个域范围内访问了云功能的默认服务帐户 我已授权以下范围: 个人资料、电子邮件、,https://mail.google.com/,https://www.googleapis.com/auth/gmail.metadata, https://www.googleapis.com/auth/gmai

调用users.watch Gmail API时收到400个错误请求,请从GCP Cloud函数

我正在尝试在用户GSuite电子邮件帐户上自动调用watch()。我已经按照下面链接中概述的步骤,在整个域范围内访问了云功能的默认服务帐户

我已授权以下范围:
个人资料、电子邮件、,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

部署的云功能代码:

exports.watchEmail = async () => {
  console.info('authenticating');

  const auth = await google.auth.getClient({
    scopes: ['profile',
      'email',
      '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'],
  });

  console.info('<-- authenticated');

  console.info('watch on email', 'no-reply@telico.ca');
  const api = google.gmail({ version: 'v1', auth });
  const response = await api.users.watch({
    userId: '<USER_EMAIL>',
    requestBody: {
      topicName: 'projects/<PROJECT_ID>/topics/processEmail',
      labelIds: ["INBOX"]
    }
  });
  console.info('<-- watch on file', JSON.stringify(response));
};
exports.watchEmail=async()=>{
console.info(“身份验证”);
const auth=wait google.auth.getClient({
作用域:['profile',
“电子邮件”,
'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'],
});

console.info('第一项。删除对默认服务帐户的更改。根据您更改的默认帐户,每个实例都将具有这些权限。创建一个新的服务帐户,分配域范围的委派,并将该服务帐户分配给函数。接下来,您为服务帐户分配了太多的作用域。请确定是哪一个您需要并且只使用该帐户。您基本上授予了everyone在G Suite中模拟、阅读、发送和删除每个人的电子邮件的权限。第一项。删除对默认服务帐户的更改。根据您更改的默认帐户,每个实例都将具有这些权限。创建新的服务帐户,分配域范围的删除权限然后,您为该服务帐户分配了太多的作用域。请找出您需要的作用域并仅使用该作用域。您基本上授予了everyone在G Suite中模拟、读取、发送和删除每个人的电子邮件的权限。