title: PHP - Google Drive API HTTP Response
body: <p>I'am making some script for download my file in google drive.</p>
  
  <p>here my test.php </p>
  
  <pre><code>require_once 'google-api-php-client/Google_Client.php';
  require_once 'google-api-php-client/contrib/Google_DriveService.php';
  $drive = new Google_Client();
  $drive-&gt;setClientId('709390325823-6bljk00f39xxxxx6jg3ji.apps.googleusercontent.com');
  $drive-&gt;setClientSecret('UL07mxxxxx01eA'); 
  $drive-&gt;setRedirectUri('http://xxx');
  $drive-&gt;setScopes(array('https://www.googleapis.com/auth/drive'));
  $drive-&gt;setAccessType('offline');
  $gdrive = new Google_DriveService($drive);
  $url = $drive-&gt;createAuthUrl();
   $token = $drive-&gt;authenticate($authorizationCode);
  $fileId = "0B9LPSEw89uQNQVNuUzdwM2hFMlk";
  $file = $gdrive-&gt;files-&gt;get($fileId);
        $downloadUrl = $file-&gt;downloadUrl;
  
   if ($downloadUrl) {
   $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
  $io = $drive-&gt;getIo();
   $httpRequest = $io-&gt;makeRequest($request);
   if ($httpRequest-&gt;getResponseHttpCode() == 200) {
   return $httpRequest-&gt;getResponseBody();
  } else {
  
   error_log("Error Downloading Attachment - HTTP ResponseCode:".$httpRequest-&gt;getResponseHttpCode());
  error_log("ContentUrl:         ".$attachment-&gt;getContentUrl());
  error_log("ContentUrl:         ".$attachment-&gt;getContentUrl());
  error_log("ContentType:        ".$attachment-&gt;getContentType());
  error_log("id                  ".$attachment-&gt;getId());
  error_log("IsProcessing:       ".(int)$attachment-&gt;getIsProcessingContent());
    return null;
  }
  
   } else {
  // An error occurred.
  }
  </code></pre>
  
  <p>everything looks fine when i run with out downloadUrl, it show downloadUrl and token</p>
  
  <blockquote>
    <p><a href="https://doc-0g-1s-docs.googleusercontent.com/docs/securesc/qjrgdcogjm0ajgdp4fnjceh8pfg486sg/u39dld0fisj9v0b3ih1nmchqp4495gdl/1473127200000/02390580194345273532/02390580194345273532/0B9LPSEw89uQNQVNuUzdwM2hFMlk?e=download&amp;gd=true&amp;access_token=ya29.Ci9WAxf99iwravP2CMmXEaYJWZb-1Y2Dxze1HToAyLb0_JJGrdVjFA5goQVBVRmWKg" rel="nofollow">https://doc-0g-1s-docs.googleusercontent.com/docs/securesc/qjrgdcogjm0ajgdp4fnjceh8pfg486sg/u39dld0fisj9v0b3ih1nmchqp4495gdl/1473127200000/02390580194345273532/02390580194345273532/0B9LPSEw89uQNQVNuUzdwM2hFMlk?e=download&amp;gd=true&amp;access_token=ya29.Ci9WAxf99iwravP2CMmXEaYJWZb-1Y2Dxze1HToAyLb0_JJGrdVjFA5goQVBVRmWKg</a></p>
  </blockquote>
  
  <p>but it show error </p>
  
  <blockquote>
    <p>Fatal error: Call to a member function getResponseHttpCode() on a non-object in</p>
  </blockquote>
  
  <p>what function http response in api google v2? Am I wrong to call function or something missing?</p>
  
  <p>Hope you guys give some advice. thanks</p>