谷歌日历:错误:超过未经验证使用的每日限制



我正在尝试遵循谷歌文档中提供的谷歌日历api nodejs示例(https://developers.google.com/calendar/quickstart/nodejs)访问我的主要谷歌日历事件,我得到了这个错误:"超过未经验证使用的每日限制。继续使用需要注册。">

我知道我正在正确地完成OAuth流程,因为我的具有日历访问权限的项目列在这里:https://myaccount.google.com/permissions?pli=1.

以下是我的范围:

const SCOPESAUTH = [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly',
'https://www.googleapis.com/auth/calendar.events'

];

在OAuth同意屏幕选项卡的开发人员控制台中,我没有设置这一部分中的作用域:"谷歌API的作用域"。当我尝试设置它们时,它说谷歌必须批准对这些敏感作用域的访问。然而,同意屏幕上并没有显示:"未经验证的应用程序。"该应用程序正在开发中,而不是生产中。

谷歌的文档说:"dailyLimitExceeded错误表明你的项目已经达到API的礼貌限制。"在开发者控制台的Quotas页面上,我的使用记录为0。我已经启用了谷歌日历API。

以下是OAuth云功能:

const functionsOauthClient = new OAuth2Client(CONFIG_CLIENT_ID, CONFIG_CLIENT_SECRET,
FUNCTIONS_REDIRECT);
// visit the URL for this Function to request tokens
exports.authgoogleapi = functions.https.onRequest((req, res) => {
// req.query.id === device id of the user
res.set('Cache-Control', 'private, max-age=0, s-maxage=0');
res.redirect(functionsOauthClient.generateAuthUrl({
access_type: 'offline',
scope: SCOPESAUTH,
prompt: 'consent',
state: req.query.id
}));
});

// redirect URI
exports.oauthcallback = functions.https.onRequest(async (req, res) => {
res.set('Cache-Control', 'private, max-age=0, s-maxage=0');
const code = req.query.code;
try {
const {tokens} = await functionsOauthClient.getToken(code);
// store the tokens for retrieval by client app that is then sent to the getEvents cloud cloud unction
admin.database().ref(`Devices/${req.query.state}/api_tokens`).set(tokens);
return res.status(200).send('App successfully configured with new Credentials.');
} catch (error) {
return res.status(400).send(error);
}
});

对oauthcallback的调用返回状态200。

下面是引发错误的代码。注意,req.body.token是在OAuth流期间生成的,保存到Firebase,然后作为参数传递给这个谷歌云函数。

exports.getEvents = functions.https.onRequest((req, res) => {
...
const authClient = new OAuth2Client(CONFIG_CLIENT_ID, CONFIG_CLIENT_SECRET, FUNCTIONS_REDIRECT);
authClient.setCredentials(req.body.token);
const calendar = google.calendar({version: 'v3', authClient});
return calendar.events.list({
calendarId: 'primary',
timeMin: (new Date()).toISOString(),
maxResults: 10,
singleEvents: true,
orderBy: 'startTime',
}, (err, result) => {...

有什么建议吗?谢谢

我发现了问题。

const calendar = google.calendar({version: 'v3', authClient})

应该是:

const calendar = google.calendar({version: 'v3', auth: authClient})

相关内容

最新更新