Archivo de descarga de API de Google Drive, código de respuesta http 200 pero el cuerpo de respuesta está vacío

Sorry if this is a stupid question but I´m new here and I don´t know how to follow.

I´ve implemented the support of Google drive in our server in php that provides support to our apps in Android and IOs, we can upload files to Google Drive or delete them with no issues, and when we are downloading the file, it looks like the httpResponseCode is correct 200 and the responseHeader too but the responseBody is empty.

I put here the response from Google Drive Server in case someone has any idea. thanks

 apiHttpRequest Object
        [batchHeaders:apiHttpRequest:private] => Array
                [Content-Type] => application/http
                [Content-Transfer-Encoding] => binary
                [MIME-Version] => 1.0
                [Content-Length] => 

        [url:protected] =>
        [requestMethod:protected] => GET
        [requestHeaders:protected] => Array
                [authorization] => Bearer ya29.AHES6ZQwIuu8ZhP8Uk389Sgo5NELnvArjzAC362ByzEsh2qa_gjDvJw

        [postBody:protected] => 
        [userAgent:protected] => google-api-php-client/0.5.0
        [responseHttpCode:protected] => 200
        [responseHeaders:protected] => Array
                [server] => HTTP Upload Server Built on Aug 15 2012 18:03:01 (1345078981)
                [access-control-allow-origin] => *
                [access-control-allow-credentials] => false
                [access-control-allow-headers] => authorization
                [access-control-allow-methods] => GET,OPTIONS
                [content-type] => video/quicktime
                [content-disposition] =>  attachment;filename="VID_20120827_105737.mp4";filename*=UTF-8''VID_20120827_105737.mp4
                [content-length] => 2768422
                [date] => Tue, 28 Aug 2012 00:15:26 GMT
                [expires] => Tue, 28 Aug 2012 00:15:26 GMT
                [cache-control] => private, max-age=0

        [responseBody:protected] =>

Now the code that I´m using:

   public function GetFile($fileId) {
     $fileVars = null;
     try {
        * Retrieve metadata for the file specified by $fileId.
       $file = $this->service->files->get($fileId);
       $fileVars = get_object_vars($file);

        * Retrieve the file's content using download URL specified in metadata.
       $downloadUrl = $file->getDownloadUrl();
       error_log('Download URL file from Drive: ' . $downloadUrl);
       if ($downloadUrl) {
         $request = new apiHttpRequest($downloadUrl, 'GET', null, null);
         $httpRequest = apiClient::$io->authenticatedRequest($request);
         error_log(print_r($httpRequest, 1));

         if ($httpRequest->getResponseHttpCode() == 200) {
           $content = $httpRequest->getResponseBody();
           $fileVars['content'] = $content?($content):'';
         } else {
           // An error occurred.
           return null;
       } else {
         // The file doesn't have any content stored on Drive.
         return null;

     } catch (apiServiceException $e) {
        * Log error and re-throw
       error_log('Error retrieving file from Drive: ' . $e->getMessage());
       throw $e;
     return json_encode($fileVars);

preguntado el 28 de agosto de 12 a las 10:08

Could you try doing the same request manually using cURL? That will tell us if there is an issue on the PHP side or on the API side. The request should look like: curl -H 'Authorization: Bearer <access_token>' -

thanks Nivco, I believe I just found the problem, I guess a combination of me being new to php and old google code example didn't work but in favor of google the new code example for get files is much better and works. Happy to see it working, but I feel bad because it is just an stupid issue between binary coding and string as I said in my first sentence. Thank you very much for responding my email and trying to help. -

You're welcome. I'm glad you have it working! -

0 Respuestas

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.