Google Service Exception

Hi Experts,

I am trying to use the Google Calendar API with the Following code

    require_once __DIR__ . '/vendor/autoload.php';
    $client = new Google_Client();
    $client->setApplicationName('Google Calendar API PHP Quickstart');
    $client->setAuthConfig(__DIR__ . '/client_secret.json');
    $calendar = new Google_Service_Calendar($client);
    $events = $calendar->events->listEvents('');
    print_variable($events, 'Google Calendar Events');
function print_variable($var, $label, $raw = true){

    echo '<br>=========START=========<br>';
    echo '<b>' . $label . '</b>';

    if ($raw == true) echo '<pre>';


    if ($raw == true) echo '</pre>';
    echo '<br>=========END=========<br>';

Open in new window

But I getting the following error:
PHP Fatal error:  Uncaught Google_Service_Exception: {
 "error": {
  "errors": [
    "domain": "usageLimits",
    "reason": "dailyLimitExceededUnreg",
    "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup.",
    "extendedHelp": ""
  "code": 403,
  "message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."
 in C:\inetpub\wwwroot\test\gmail_calendar\vendor\google\apiclient\src\Google\Http\REST.php:118
Stack trace:
#0 C:\inetpub\wwwroot\test\gmail_calendar\vendor\google\apiclient\src\Google\Http\REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#1 C:\inetpub\wwwroot\test\gmail_calendar\vendor\google\apiclient\src\Google\Task\Runner.php(181): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...')
#2 C:\inetpub\wwwroot\test\gmail_calendar\vendor\google\apiclient\src\ in C:\inetpub\wwwroot\test\gmail_calendar\vendor\google\apiclient\src\Google\Http\REST.php on line 118

Open in new window

My first thoughts was to go under my Google API console and under Domain Verification Add a domain. This referred me to Webmaster Central, but I cannot add my localhost. Do I need to use a real domain only, and can I use a subdomain? However, maybe I am  completely on the wrong track?

Any help will be appreciated.
APD TorontoSoftware DeveloperAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
It means that you need a Google Calendar API license to use the service because you exceeded the daily limit of API access -OR- you haven't added the Calander API to your account yet?

Check your Google Dashboard:

If you already have the account setup for Calander API, you might need a paid license:

So that must mean the API key exceeded the 1M access limit
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
You just need to go through the signup process + use a valid license key for access + then stay within your access limits.

The message above is clear...

"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

Your App is exceeding the daily usage limit for anonymous version. You have to signup for the number of calls you're making to work correctly.
APD TorontoSoftware DeveloperAuthor Commented:
The quota is 1M/dday, today I made zero.

Also, why is it  saying

"message": "Daily Limit for Unauthenticated Use Exceeded. Continued use requires signup."

.When on line 6 I (think) am using the .json file that I downloaded from the console?
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference ithrough the Colors of STEM program.

APD TorontoSoftware DeveloperAuthor Commented:
How do I

You just need to go through the signup process + use a valid license key for access + then stay within your access limits.

As stated I am using the provided .json file.
NerdsOfTechTechnology ScientistCommented:
The 1M quota is for authenticated users, +1M for authenticated paid users, unauthenticated users have no access (quota of zero) to Google APIs (including Calander).


To run this quickstart, you'll need:

PHP 5.4 or greater with the command-line interface (CLI) and JSON extension installed.
The Composer dependency management tool.
Access to the internet and a web browser.
A Google account with Google Calendar enabled.
Chris StanyonWebDevCommented:
Nowhere in your code are you actually handling any authentication. The client_secret.json file simply specifies the details of your App, along with the callback used AFTER a user has authenticated themselves.

The Google API uses oAuth for it's authentication, and you have a couple of options here, depending on what you want your app to do.

If you want your app (webpage) to show your own Events, then you would need to Authenticate with a Service Account. If you want your app to show your user's Events when they visit your page, then you would need to Authenticate with a Client ID (and a callback script).

Let us know exactly what you're trying to do and we'll be able to point you in the right direction.
APD TorontoSoftware DeveloperAuthor Commented:
This is a web-based app for internal use by staff.  The Google Calendar portion will be for staff to schedule future appointments.

So, in this, its working with my own calendar events.
Chris StanyonWebDevCommented:
OK. Pretty sure in that case, you need to set up a Service Account.

Log in to your Google API Console, select Credentials and create a new Service Account Key. Give it a name and a role (probably Project / Editor will do). Make sure JSON is selected and click on Create. Save the JSON file to your app folder (ideally, accessible by your web app but not publicly accessible!).

Once you've created the Service Account, you'll see a Service Account ID - it looks like an email address. Basically, you'll need to login to your Google Calendar and share it with that email address. When sharing your calendar, make sure you select the correct permissions.

Once that's done, you can access the calendar by Authenticating with the JSON file you downloaded. Something like this:

ini_set('display_errors', 1);

require_once __DIR__ . '/vendor/autoload.php';

$client = new Google_Client();
$client->setApplicationName('My Google Calendar');
$client->setAuthConfig('service_key.json'); // the JSON file you downloaded - KEEP IT SAFE!

$service = new Google_Service_Calendar($client);

$params = array(
  'maxResults' => 5,
  'orderBy' => 'startTime',
  'singleEvents' => TRUE,
  'timeMin' => date('c'),

$results = $service->events->listEvents('', $params);

Open in new window

This gets you the results, and you can then loop through them as needed:

<?php if (count($results->getItems()) == 0): ?>

    <h2>No upcoming events found.</h2>

<?php else: ?>

    <h2>Upcoming events:</h2>

    <?php foreach ($results->getItems() as $event): ?>
            $start = $event->start->dateTime;
            if (empty($start)) {
                $start = $event->start->date;

        <p><?php printf("%s (%s)\n", $event->getSummary(), $start) ?></p>
    <?php endforeach; ?>

<?php endif; ?>

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
APD TorontoSoftware DeveloperAuthor Commented:
Thank You!!!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.