Search code examples
google-calendar-apigoogle-oauth

Google Calendar: Error: Daily Limit for Unauthenticated Use Exceeded


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.


Solution

  • I found the problem.

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

    should be:

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