How do I connect to the Google Calendar API without the oAuth authentication?

If I’m not wrong, they’ve launched Service Account for this now:


Here’s the modification from their Prediction API

    require_once "google-api-php-client/src/Google_Client.php";
    require_once "google-api-php-client/src/contrib/Google_CalendarService.php";

    const CLIENT_ID = '...';
    const SERVICE_ACCOUNT_NAME = '...';

    // Make sure you keep your key.p12 file in a secure location, and isn't
    // readable by others.
    const KEY_FILE = '...';

    $client = new Google_Client();

    if (isset($_SESSION['token'])) {

    // Load the key in PKCS 12 format (you need to download this from the
    // Google API Console when the service account was created.
    $key = file_get_contents(KEY_FILE);
    $client->setAssertionCredentials(new Google_AssertionCredentials(
        array('', ""),

    $service = new Google_CalendarService($client);

    //Save token in session
    if ($client->getAccessToken()) {
      $_SESSION['token'] = $client->getAccessToken();

    //And now you can use the code in their PHP examples, like: $service->events->listEvents(...)

Leave a Comment