title: Google API client authorization: Internal Server Error 500
body: <p>I'm using an OAuth 2.0 for Web Server Applications example code on remote web server.</p>
  
  <p>$client->authenticate(...) causes </p>
  
  <blockquote>
    <p>Internal Server Error 500.</p>
  </blockquote>
  
  <p>No idea why, can you help me please?</p>
  
  <p>Here is the web address: <a href="http://imperiousgroup.com/gdrive/" rel="nofollow noreferrer">http://imperiousgroup.com/gdrive/</a></p>
  
  <p>And here is the code:</p>
  
  <pre><code>//index.php
  
  require_once(__DIR__ ."/api/vendor/autoload.php");
  
  session_start();
  
  $client = new Google_Client();
  
  $client-&gt;setAuthConfig('client_secrets.json');
  
  $client-&gt;addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
  
  if (isset($_SESSION['access_token']) &amp;&amp; $_SESSION['access_token']) {
  
      $client-&gt;setAccessToken($_SESSION['access_token']);
  
      $drive_service = new Google_Service_Drive($client);
  
      $files_list = $drive_service-&gt;files-&gt;listFiles(array())-&gt;getItems();
  
      echo json_encode($files_list);
  
  } else {
  
      $redirect_uri = 'http://' . $_SERVER['HTTP_HOST'] . '/gdrive/oauth2callback.php';
  
      header('Location: ' . filter_var($redirect_uri, FILTER_SANITIZE_URL));
  
  }
  
  
  //oauth2callback.php
  
  require_once __DIR__ .'/api/vendor/autoload.php';
  
  session_start();
  
  $client = new Google_Client();
  
  $client-&gt;setAuthConfigFile('client_secrets.json');
  
  $client-&gt;setRedirectUri('http://' . $_SERVER['HTTP_HOST'] . '/gdrive/oauth2callback.php');
  
  $client-&gt;addScope(Google_Service_Drive::DRIVE_METADATA_READONLY);
  
  if (!isset($_GET['code'])) {
  
      $auth_url = $client-&gt;createAuthUrl();
  
      header('Location: ' . filter_var($auth_url, FILTER_SANITIZE_URL));
  
  } else {
  
      $client-&gt;authenticate($_GET['code']);
  
  }
  </code></pre>