title: Allow my user to add meeting in my calendar with Google Calendar API with PHP without auth
body: <p>I am working on a app that allows my users to schedule/reschedule Calendar events using one of my Google calendars, where I don’t need the users to authenticate themselves with Google. What i need to use is the Google Calendar API with a service account.</p>
  <p>I tried to write something with api v2 but I had a problem, so I would like to know if you could direct me to a tutorial or an example, or just an example of insertion</p>
  <pre class="lang-php prettyprint-override"><code>&lt;?php
  
  require_once './google-api-php-client-2.2.2/vendor/autoload.php';
  
  
  session_start();
  /************************************************   */
  
  $client_id = '751416246659ae431430560098c25ba433c3e483';
  $Email_address = ' testecalendar@spartan-grail-241202.iam.gserviceaccount.com';
  $key_file_location = './credentials.json';
  
  $client = new Google_Client();
  $client-&gt;setApplicationName(&quot;Client_Library_Examples&quot;);
  $key = file_get_contents($key_file_location);
  
  // separate additional scopes with a comma   
  $scopes = &quot;https://www.googleapis.com/auth/calendar.readonly&quot;;
  $client-&gt;setAuthConfig('./credentials.json');
  
  
  $service = new Google_Service_Calendar($client);
  
  ?&gt;
  
  &lt;html&gt;
  
  &lt;body&gt;
  
      &lt;?php
      $calendarList  = $service-&gt;calendarList-&gt;listCalendarList();
  
      while (true) {
          foreach ($calendarList-&gt;getItems() as $calendarListEntry) {
  
              echo $calendarListEntry-&gt;getSummary() . &quot;&lt;br&gt;\n&quot;;
  
  
              // get events 
              $events = $service-&gt;events-&gt;listEvents($calendarListEntry-&gt;id);
  
  
              foreach ($events-&gt;getItems() as $event) {
                  echo &quot;-----&quot; . $event-&gt;getSummary() . &quot;&lt;br&gt;&quot;;
              }
          }
          $pageToken = $calendarList-&gt;getNextPageToken();
          if ($pageToken) {
              $optParams = array('pageToken' =&gt; $pageToken);
              $calendarList = $service-&gt;calendarList-&gt;listCalendarList($optParams);
          } else {
              break;
          }
      }
  
      ?&gt;
  
  </code></pre>
  <p>I got this error:</p>
  <blockquote>
  <p>Fatal error: Uncaught Google_Service_Exception: { &quot;error&quot;: { &quot;errors&quot;: [ { &quot;domain&quot;: &quot;global&quot;, &quot;reason&quot;: &quot;required&quot;, &quot;message&quot;: &quot;Login Required&quot;, &quot;locationType&quot;: &quot;header&quot;, &quot;location&quot;: &quot;Authorization&quot; } ], &quot;code&quot;: 401, &quot;message&quot;: &quot;Login Required&quot; } } in /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Http/REST.php:118 Stack trace: #0 /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Http/REST.php(94): Google_Http_REST::decodeHttpResponse(Object(GuzzleHttp\Psr7\Response), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #1 /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Task/Runner.php(176): Google_Http_REST::doExecute(Object(GuzzleHttp\Client), Object(GuzzleHttp\Psr7\Request), 'Google_Service_...') #2 /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Http/REST.php(58): Google_Task_Runner-&gt;run() #3 /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Client.php(798): Google_Http_RES in /Users/macbook/Desktop/testcal/google-api-php-client-2.2.2/src/Google/Http/REST.php on line 118</p>
  </blockquote>