Download Google Drive API下载文件,http响应代码200,但响应库为空

Download Google Drive API下载文件,http响应代码200,但响应库为空,download,google-drive-api,google-api-client,Download,Google Drive Api,Google Api Client,对不起,如果这是一个愚蠢的问题,但我是新来的,我不知道如何遵循 我已经在我们的服务器上用php实现了对Google drive的支持,这为我们在Android和IOs上的应用提供了支持,我们可以将文件上传到Google drive或删除它们,没有任何问题。当我们下载文件时,看起来httpResponseCode是正确的,responseHeader也是正确的,但ResponseBook是空的 我把谷歌硬盘服务器的回复放在这里,以防有人知道。谢谢 apiHttpRequest Object

对不起,如果这是一个愚蠢的问题,但我是新来的,我不知道如何遵循

我已经在我们的服务器上用php实现了对Google drive的支持,这为我们在Android和IOs上的应用提供了支持,我们可以将文件上传到Google drive或删除它们,没有任何问题。当我们下载文件时,看起来httpResponseCode是正确的,responseHeader也是正确的,但ResponseBook是空的

我把谷歌硬盘服务器的回复放在这里,以防有人知道。谢谢

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

        [url:protected] => https://doc-0s-6s-docs.googleusercontent.com/docs/securesc/3h10lch354ufu4pkrusuk27smk7k4ifq/qp3b555lfchhfmpfodjv4mcpbug1vol6/1346112000000/12488086635796486161/12488086635796486161/0B_cf3F02DuErM3V3b0o4WnYyNTA?h=16653014193614665626&e=download&gd=true
        [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] =>
现在我使用的代码是:

   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);
    }

您可以尝试使用cURL手动执行相同的请求吗?这将告诉我们PHP端或API端是否存在问题。请求应该是这样的:curl-H'Authorization:Bearer…谢谢Nivco,我相信我刚刚发现了问题,我猜我是php新手,旧的google代码示例组合不起作用,但对google有利的是,get文件的新代码示例更好,更有效。很高兴看到它工作,但我感觉很糟糕,因为正如我在第一句话中所说的,这只是二进制编码和字符串之间的一个愚蠢问题。非常感谢您回复我的电子邮件并尽力提供帮助。不客气。我很高兴你有它的工作!