title: Google task api authentication not working php
body: <p>I have a file called TasksLogin.php which lets me login</p>
  
  <pre><code>session_start();
  require_once 'google-api-php-client/src/Google_Client.php';
  require_once 'google-api-php-client/src/contrib/Google_TasksService.php';
  $client = new Google_Client();
  $client-&gt;setClientId('xxxxx.apps.googleusercontent.com');
  $client-&gt;setClientSecret('xxxxxxxxx');
  $client-&gt;setRedirectUri('http://xxxxxxxxx/Tasks/TaskVis.html');
  $client-&gt;setApplicationName("TasksForMike");
  $tasksService = new Google_TasksService($client);
  
  if (isset($_REQUEST['logout'])) {
    unset($_SESSION['token']);
  }
  
  if (isset($_SESSION['token'])) {
    $client-&gt;setAccessToken($_SESSION['token']);
  
  } else {
    $client-&gt;setAccessToken($client-&gt;authenticate($_GET['code']));
    $_SESSION['token'] = $client-&gt;getAccessToken();
  
  }
  
  if (isset($_GET['code'])) {
    $redirect = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
    header('Location: ' . filter_var($redirect, FILTER_SANITIZE_URL));
  }
  ?&gt;
  &lt;?php $_SESSION['token'] = $client-&gt;getAccessToken(); ?&gt;
  </code></pre>
  
  <p>That seems to work because it redirects to TaskVis.php
  But in TasksVis.php I call:</p>
  
  <pre><code>$(document).ready(function() {
    $.get("tasks.php", function(data){
  var json = data;
  });
   });
  </code></pre>
  
  <p>which is the php file that gets the tasks and packages them up in a json object.
  but in tasks.php, I have this code that crashes:</p>
  
  <pre><code>session_start();
  require_once 'google-api-php-client/src/Google_Client.php';
  require_once 'google-api-php-client/src/contrib/Google_TasksService.php';
  $client = new Google_Client();
  $client-&gt;setClientId('xxxxxx.apps.googleusercontent.com');
  $client-&gt;setClientSecret('xxxxxxxxxxxxxxx');
  $client-&gt;setRedirectUri('http://xxxxxxxxx/Tasks/TaskVis.html');
  $client-&gt;setApplicationName("TasksForMike");
  $tasksService = new Google_TasksService($client);
  
  if (isset($_REQUEST['logout'])) 
  {
    unset($_SESSION['token']);
  }
   if (isset($_GET['code'])) {
    $client-&gt;authenticate($_GET['code']);
    echo "hh";
    die();
    $_SESSION['token'] = $client-&gt;getAccessToken();
    header('Location: http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
  
  }
  ?&gt;
  </code></pre>
  
  <p>the "die" never runs and I get a 500 server error. Since the code is in the query string, why is the <code>$client-&gt;authenticate($_GET['code']);</code> failing ? I am trying to seperate the data code from the rendering.</p>