I'm trying to follow the google calendar api nodejs example provided in google's documentation (https://developers.google.com/calendar/quickstart/nodejs) to access my primary google calendar events and I get this error: "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
I know I am getting through the OAuth flow correctly because my project with calendar access is listed here: https://myaccount.google.com/permissions?pli=1.
Here are my scopes:
const SCOPESAUTH = [
'https://www.googleapis.com/auth/calendar',
'https://www.googleapis.com/auth/calendar.readonly',
'https://www.googleapis.com/auth/calendar.events'
];
In the developer's console in the OAuth consent screen tab I have NOT set the scopes in this section: "Scopes for Google APIs." When I try to set them, it says google must approve access to these sensitive scopes. However, the consent screen does NOT say: "unverified app." The app is in development not production.
Google's doc say: "A dailyLimitExceeded error indicates that the courtesy API limit for your project has been reached." On the Quotas page in the developers console my usage is recorded as 0. I've enabled the Google Calendar API.
Here are the OAuth cloud functions:
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);
}
});
The call to oauthcallback returns status 200.
Below is the code that throws the error. Note, req.body.token was produced during the OAuth flow, saved to Firebase and then passed as a parameter to this google cloud function.
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) => {...
Any suggestions? Thanks.
getAccessToken
function to set the token. Please provide the full code you're using for the authentication flow. – Andres Duartereq.body.token
right before using it insetCrendentials
, it should give you a valid refresh token you can use to test the calendar list request in google playground, did it work for you there? Also, are you consenting the access manually? As following the quickstart, you need to visit the redirect URI with your user signed in and grant the access to the app for the first time by copying and pasting the givencode
variable. – Andres Duarte