Google Calendar: Error: Daily Limit for Unauthenticated Use Exceeded
Google Calendar: Error: Daily Limit for Unauthenticated Use Exceeded
我正在尝试按照 google 文档 (https://developers.google.com/calendar/quickstart/nodejs) 中提供的 google 日历 api nodejs 示例来访问我的主要 google 日历事件,我收到此错误:"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
我知道我正确地通过了 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 同意屏幕选项卡中,我没有在此部分中设置范围:"Scopes for Google APIs." 当我尝试设置它们时,它说 google 必须批准对这些敏感内容的访问范围。但是,同意屏幕并未显示:"unverified app." 该应用程序正在开发中,而非生产中。
Google 的文档说:"A dailyLimitExceeded error indicates that the courtesy API limit for your project has been reached." 在开发人员控制台的配额页面上,我的使用记录为 0。我启用了 Google 日历 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 returns status 200.
下面是抛出错误的代码。请注意,req.body.token 是在 OAuth 流程中生成的,保存到 Firebase,然后作为参数传递给此 google 云函数。
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})
我正在尝试按照 google 文档 (https://developers.google.com/calendar/quickstart/nodejs) 中提供的 google 日历 api nodejs 示例来访问我的主要 google 日历事件,我收到此错误:"Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
我知道我正确地通过了 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 同意屏幕选项卡中,我没有在此部分中设置范围:"Scopes for Google APIs." 当我尝试设置它们时,它说 google 必须批准对这些敏感内容的访问范围。但是,同意屏幕并未显示:"unverified app." 该应用程序正在开发中,而非生产中。
Google 的文档说:"A dailyLimitExceeded error indicates that the courtesy API limit for your project has been reached." 在开发人员控制台的配额页面上,我的使用记录为 0。我启用了 Google 日历 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 returns status 200.
下面是抛出错误的代码。请注意,req.body.token 是在 OAuth 流程中生成的,保存到 Firebase,然后作为参数传递给此 google 云函数。
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})