title: Add events to my google calendar from my website
body: <p>I have created a php page with fullcalendar jquery plugin which allow website users to book time. On background I'm storing event into my DB and then using Google calendar API creating same event to my google calendar.</p>
  
  <p>But my implementation is asking user to login into their google account and creating event on user's calendar. How can I achieve to create user event in my(website owner's) google calendar "seamlessly"?</p>
  
  <p>my code is as below:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  require_once __DIR__ . '/vendor/autoload.php';
  
  define('APPLICATION_NAME', 'Google Calendar');
  define('CREDENTIALS_PATH', '~/.credentials/calendar-php-quickstart.json');
  define('CLIENT_SECRET_PATH', __DIR__ . '/client_secret.json');
  // If modifying these scopes, delete your previously saved credentials
  // at ~/.credentials/calendar-php-quickstart.json
  define('SCOPES', implode(' ', array(
    Google_Service_Calendar::CALENDAR)
  ));
  
  
  /**
   * Returns an authorized API client.
   * @return Google_Client the authorized client object
   */
  function getClient() {
      $client = new Google_Client();
      $client-&gt;setApplicationName(APPLICATION_NAME);
      $client-&gt;setScopes(SCOPES);
      $client-&gt;setAuthConfigFile(CLIENT_SECRET_PATH);
      $client-&gt;setAccessType('offline');
      // Load previously authorized credentials from a file.
      $credentialsPath = expandHomeDirectory(CREDENTIALS_PATH);
  
  /*if (file_exists($credentialsPath)) {
    $accessToken = file_get_contents($credentialsPath);
  } else {*/
  
      if(!$_REQUEST['code']) {
          $authUrl = $client-&gt;createAuthUrl();
          //printf("Open the following link in your browser:\n%s\n", $authUrl);
          header("Location:".$authUrl);
      }
      $authCode = $_REQUEST['code'];
      $accessToken = $client-&gt;authenticate($authCode);
  
      // Store the credentials to disk.
      /*if(!file_exists(dirname($credentialsPath))) {
        mkdir(dirname($credentialsPath), 0700, true);
      }
      file_put_contents($credentialsPath, $accessToken);*/
      //printf("Credentials saved to %s\n", $credentialsPath);
  //}
  $client-&gt;setAccessToken($accessToken);
  
  // Refresh the token if it's expired.
  if ($client-&gt;isAccessTokenExpired()) {
  $client-&gt;refreshToken($client-&gt;getRefreshToken());
  file_put_contents($credentialsPath, $client-&gt;getAccessToken());
  }
  return $client;
  }
  /**
  * Expands the home directory alias '~' to the full path.
  * @param string $path the path to expand.
  * @return string the expanded path.
  */
  function expandHomeDirectory($path) {
    $homeDirectory = getenv('HOME');
    if (empty($homeDirectory)) {
      $homeDirectory = getenv("HOMEDRIVE") . getenv("HOMEPATH");
    }
    return str_replace('~', realpath($homeDirectory), $path);
  }
  
  // Get the API client and construct the service object.
  $client = getClient();
  $service = new Google_Service_Calendar($client);
  
  
  $event = new Google_Service_Calendar_Event(array(
    'summary' =&gt; $_SESSION['cal-data']['fname']." ".$_SESSION['cal-data']['lname'],
    'location' =&gt; $_SESSION['cal-data']['address'],
    'description' =&gt; "Contact: ".$_SESSION['cal-data']['phoneno']." for ".$_SESSION['cal-data']['title'],
    'start' =&gt; array(
      'dateTime' =&gt; $_SESSION['cal-data']['starttm'],
      //'timeZone' =&gt; 'America/Los_Angeles',
    ),
    'end' =&gt; array(
      'dateTime' =&gt; $_SESSION['cal-data']['endtm'],
      //'timeZone' =&gt; 'America/Los_Angeles',
    ),
    /*'recurrence' =&gt; array(
      'RRULE:FREQ=DAILY;COUNT=2'
    ),*/
    'attendees' =&gt; array(
      array('email' =&gt; $_SESSION['cal-data']['email'])
    ),
    'reminders' =&gt; array(
      'useDefault' =&gt; FALSE,
      'overrides' =&gt; array(
        array('method' =&gt; 'email', 'minutes' =&gt; 24 * 60),
        array('method' =&gt; 'popup', 'minutes' =&gt; 10),
      ),
    ),
  ));
  
  $calendarId = 'xxxxxxxxxxxxxxxxxxxxx@group.calendar.google.com';
  $event = $service-&gt;events-&gt;insert($calendarId, $event);
  //printf('Event created: %s\n', $event-&gt;htmlLink);
  unset($_SESSION['cal-data']);
  
  header("Location: next-page.php");
  </code></pre>