title: Could not json decode the token
body: <p>Here is my code, </p>
  
  <pre><code>   &lt;?php
  session_start(); 
  $url = 'http://localhost:8080/google-drive/index.php?msg=Successfully Uploaded!'; 
  require_once 'google-api-php-client/src/Google_Client.php';
  require_once 'google-api-php-client/src/contrib/Google_DriveService.php';
  $client = new Google_Client();
  
  if(isset($_POST['submit'])){ 
  $files = glob('files/*'); // get all file names
  foreach($files as $file){ // iterate files
    if(is_file($file))
      unlink($file); // delete file
  }
  
  $uploaddir = 'files/';
  $uploadfile = $uploaddir . basename($_FILES['fileToUpload']['name']);
  move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $uploadfile);
  }
  $files= array();
  $dir = dir('files');
  while ($file = $dir-&gt;read()) {
      if ($file != '.' &amp;&amp; $file != '..') {
          $files[] = $file;
      }
  }
  $dir-&gt;close();
  
  if (!empty($_POST)) {
  
      $token = file_get_contents('auth.txt');
      echo $token;
      $token = array(
      'access_token' =&gt; 'xxxxxx',
      'token_type' =&gt;'Bearer',
      'expires_in' =&gt;'3600',
      'refresh_token' =&gt; 'xxxxx',
      'created' =&gt; 'xxxxxxx'
     );
  
   $tokennew = json_encode($token);
   $client-&gt;setClientId('xxxxxxxxxx');
  $client-&gt;setClientSecret('xxxxxx');
  $client-&gt;setAccessType('offline');
  $client-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
      $client-&gt;setAccessToken($tokennew);
      $service = new Google_DriveService($client);
      $finfo = finfo_open(FILEINFO_MIME_TYPE);
      $file = new Google_DriveFile();
      foreach ($files as $file_name) {
          $file_path = 'files/'.$file_name;
          $mime_type = finfo_file($finfo, $file_path);
          $file-&gt;setTitle($file_name);
          $file-&gt;setDescription('This is a '.$mime_type.' document');
          $file-&gt;setMimeType($mime_type);
          $service-&gt;files-&gt;insert(
              $file,
              array(
                  'data' =&gt; file_get_contents($file_path),
                  'mimeType' =&gt; $mime_type
              )
          );
      }
      finfo_close($finfo);
      header('location:'.$url);
      exit;
  
  }
  include 'app.php'; 
  
  ?&gt;
  </code></pre>
  
  <p>when I run this file I got 'Uncaught exception 'Google_AuthException' with message 'Could not json decode the token'. I want to read access token from text file and pass to setAccessToken() function. access token prints well.Where am I wrong?</p>