title: Insert event to Google Calendar using php
body: <p>I'm trying to perform a cURL request to google calendar api using <a href="https://developers.google.com/google-apps/calendar/v3/reference/events/insert" rel="nofollow">their guide</a>, that says:</p>
  
  <pre><code>POST https://www.googleapis.com/calendar/v3/calendars/{name_of_my_calendar}/events?sendNotifications=true&amp;pp=1&amp;key={YOUR_API_KEY}
  
  Content-Type:  application/json
  Authorization:  OAuth 1/SuypHO0rNsURWvMXQ559Mfm9Vbd4zWvVQ8UIR76nlJ0
  X-JavaScript-User-Agent:  Google APIs Explorer
  
  {
   "start": {
    "dateTime": "2012-06-03T10:00:00.000-07:00"
   },
   "end": {
    "dateTime": "2012-06-03T10:20:00.000-07:00"
   },
   "summary": "my_summary",
   "description": "my_description"
  }
  </code></pre>
  
  <p>How am I supposed to do that in php? I wonder what parameters I should send and what constants I should use. I'm currently doing:</p>
  
  <pre><code>        $url = "https://www.googleapis.com/calendar/v3/calendars/".urlencode('{name_of_my_calendar}')."/events?sendNotifications=true&amp;pp=1&amp;key={my_api_key}";  
  
          $post_data = array(  
              "start" =&gt; array("dateTime" =&gt; "2012-06-01T10:00:00.000-07:00"),  
              "end" =&gt; array("dateTime" =&gt; "2012-06-01T10:40:00.000-07:00"),  
              "summary" =&gt; "my_summary",
              "description" =&gt; "my_description"
          );
  
          $ch = curl_init();  
          curl_setopt($ch, CURLOPT_URL, $url);  
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);  
          curl_setopt($ch, CURLOPT_POST, 1);  
          // adding the post variables to the request  
          curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);  
  
          $output = curl_exec($ch);  
  
          curl_close($ch);  
  </code></pre>
  
  <p>but the response is:</p>
  
  <pre><code>{
      error: {
          errors: [
          {
              domain: "global",
              reason: "required",
              message: "Login Required",
              locationType: "header",
              location: "Authorization"
          }
          ],
          code: 401,
          message: "Login Required"
      }
  }
  </code></pre>
  
  <p>How should I format my parameters?</p>