title: Create a Google Calendar account without being signed in
body: <p>I'm trying to create a Google calendar event when a page is refreshed.  Here's my code:</p>
  
  <pre><code>&lt;?php
  require_once '../../src/config.php';
  
  session_start();
  
  $client = new Google_Client();
  $client-&gt;setApplicationName("Google Calendar PHP Starter Application");
  
  // Visit https://code.google.com/apis/console?api=calendar to generate your
  //client id, client secret, and to register your redirect uri.
  $client-&gt;setClientId('--the client id--');
  $client-&gt;setClientSecret('--the client secret--');
  $client-&gt;setRedirectUri('http://acromediainc.acrobuild.com/calendar/google-api-php-client/examples/calendar/simple.php');
  //$client-&gt;setDeveloperKey('--the developer key--');
  $cal = new Google_CalendarService($client);
  
  
  
  if (isset($_GET['logout'])) {
    unset($_SESSION['token']);
  }
  
  if (isset($_GET['code'])) {
  $client-&gt;authenticate($_GET['code']);
  $_SESSION['token'] = $client-&gt;getAccessToken();
  header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  }
  
  if (isset($_SESSION['token'])) {
  $client-&gt;setAccessToken($_SESSION['token']);
  }
  
  if ($client-&gt;getAccessToken()) {
  $calList = $cal-&gt;calendarList-&gt;listCalendarList();
  print "&lt;h1&gt;Calendar List&lt;/h1&gt;&lt;pre&gt;" . print_r($calList, true) . "&lt;/pre&gt;";
  
  
  $_SESSION['token'] = $client-&gt;getAccessToken();
  
  $event = new Google_Event();
  $event-&gt;setSummary('Halloween');
  $event-&gt;setLocation('The Neighbourhood');
  $start = new Google_EventDateTime();
  $start-&gt;setTimeZone('America/Los_Angeles');
  $start-&gt;setDateTime('2014-4-30T10:00:00.000');
  $event-&gt;setStart($start);
  $end = new Google_EventDateTime();
  $end-&gt;setTimeZone('America/Los_Angeles');
  $end-&gt;setDateTime('2014-4-30T10:20:00.000');
  $event-&gt;setEnd($end);
  $createdEvent = $cal-&gt;events-&gt;insert('mycalendarid@group.calendar.google.com', $event);
  } else {
  $authUrl = $client-&gt;createAuthUrl();
  print "&lt;a class='login' href='$authUrl'&gt;Connect Me!&lt;/a&gt;";
  }
  </code></pre>
  
  <p>...and here's the config file:</p>
  
  <pre><code>&lt;?php
  /*
   * Copyright 2010 Google Inc.
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *     http://www.apache.org/licenses/LICENSE-2.0
   *
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  
  require_once "Google_Client.php";
  require_once "contrib/Google_CalendarService.php";
  require_once 'service/Google_ServiceResource.php';
  require_once 'service/Google_Service.php';
  require_once 'Google_Client.php';
  
  global $apiConfig;
  $apiConfig = array(
  // True if objects should be returned by the service classes.
  // False if associative arrays should be returned (default behavior).
  'use_objects' =&gt; false,
  
  // The application_name is included in the User-Agent HTTP header.
  'application_name' =&gt; 'Calendar',
  
  // OAuth2 Settings, you can get these keys at https://code.google.com/apis/console
  //'oauth2_client_id' =&gt; 'my client id',
  //'oauth2_client_secret' =&gt; 'my client secret',
  // 'oauth2_redirect_uri' =&gt; 'http://acromediainc.acro.dev/calendar/calendar.php',
  
  // The developer key, you get this at https://code.google.com/apis/console
  'developer_key' =&gt; 'my developer key',
  
  // Site name to show in the Google's OAuth 1 authentication screen.
  'site_name' =&gt; 'www.example.org',
  
  // Which Authentication, Storage and HTTP IO classes to use.
  'authClass'    =&gt; 'Google_OAuth2',
  'ioClass'      =&gt; 'Google_CurlIO',
  'cacheClass'   =&gt; 'Google_FileCache',
  
  // Don't change these unless you're working against a special development or testing environment.
  'basePath' =&gt; 'https://www.googleapis.com',
  
  // IO Class dependent configuration, you only have to configure the values
  // for the class that was configured as the ioClass above
  'ioFileCache_directory'  =&gt;
      (function_exists('sys_get_temp_dir') ?
          sys_get_temp_dir() . '/Google_Client' :
      '/tmp/Google_Client'),
  
  // Definition of service specific values like scopes, oauth token URLs, etc
  'services' =&gt; array(
    'analytics' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/analytics.readonly'),
    'calendar' =&gt; array(
        'scope' =&gt; array(
            "https://www.googleapis.com/auth/calendar",
            "https://www.googleapis.com/auth/calendar.readonly",
        )
    ),
    'books' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/books'),
    'latitude' =&gt; array(
        'scope' =&gt; array(
            'https://www.googleapis.com/auth/latitude.all.best',
            'https://www.googleapis.com/auth/latitude.all.city',
        )
    ),
    'moderator' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/moderator'),
    'oauth2' =&gt; array(
        'scope' =&gt; array(
            'https://www.googleapis.com/auth/userinfo.profile',
            'https://www.googleapis.com/auth/userinfo.email',
        )
    ),
    'plus' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/plus.login'),
    'siteVerification' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/siteverification'),
    'tasks' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/tasks'),
    'urlshortener' =&gt; array('scope' =&gt; 'https://www.googleapis.com/auth/urlshortener')
  )
  );
  </code></pre>
  
  <p>I've got the OAuth stuff commented out because I want to use the developer key instead.  Right now, my code works fine if I'm logged into my browser on the account the calendar is associated with, but if I'm logged on with another gmail account, I get an error:
  'Error calling POST <a href="https://www.googleapis.com/calendar/v3/calendars/2pnfetf7qtph9i7sq9tcfep1jk@group.calendar.google.com/events" rel="nofollow">https://www.googleapis.com/calendar/v3/calendars/2pnfetf7qtph9i7sq9tcfep1jk@group.calendar.google.com/events</a>: (404) Not Found'
  Which is basically saying it can't find the calendar with that ID.  If I try to run this code in a browser that is not logged in, the 'else' clause runs and asks the user to log in.  Is there a way to create a calendar event without being logged in to a gmail account associated with that calendar event?  Thanks.</p>