呼叫用户时收到400错误请求。通过GCP Cloud Function观看Gmail API
我正在尝试自动对用户GSuite电子邮件帐户进行watch()调用。我已经按照以下链接中概述的步骤授予了域范围内对Cloud Function的默认服务帐户的访问权限
https://developers.google.com/admin-sdk/reports/v1/guids/delegation
我已授权以下范围:
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
已部署的云功能代码:
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));
};
执行CloudFunction时,我看到Error: Bad Request at Gaxios.request
打印在日志中。