title: Google Calendar API Insert event without authorization
body: <p>I need to authorize users on my site to insert an event in our google calendar. It's a booking system, where the user selects a service,confirm, and a new event is inserted automaticly in our calendar.
  The problem is, i have an authorization button on client's page witch i don't need.</p>
  
  <pre><code>&lt;button id="authorize-button" onclick="handleAuthClick(event)"&gt;Authorize&lt;/button&gt;
  </code></pre>
  
  <p>So i think i need a service account authorization. But i don't know how to use generated json and p12 key in javascript. 
  I need a sample or at least to understand what i have to do..</p>
  
  <p>JS code:</p>
  
  <pre><code>var CLIENT_ID = '*********.apps.googleusercontent.com';
  var API_KEY = 'AIza***********************';
  var SCOPES = ["https://www.googleapis.com/auth/calendar"];
  
  function handleClientLoad() {
    gapi.client.setApiKey(API_KEY);
    window.setTimeout(checkAuth, 1);
  }
  
  function checkAuth() {
    gapi.auth.authorize({
      client_id: CLIENT_ID,
      scope: SCOPES,
      immediate: true
    }, handleAuthResult);
  }
  
  function handleAuthResult(authResult) {
    var authorizeButton = document.getElementById('authorize-button');
    if (authResult &amp;&amp; !authResult.error) {
      authorizeButton.style.visibility = 'hidden';
    } else {
      authorizeButton.style.visibility = '';
      authorizeButton.onclick = handleAuthClick;
    }
  }
  
  function handleAuthClick(event) {
    gapi.auth.authorize({
      client_id: CLIENT_ID,
      scope: SCOPES,
      immediate: false
    }, handleAuthResult);
    return false;
  }
  </code></pre>
  
  <p>P.S. - Site is on php.</p>