1

对不起,如果这是一个愚蠢的问题,但我是新来的,我不知道该怎么做。

我已经在我们的服务器中用 php 实现了对 Google Drive 的支持,它为我们在 Android 和 IO 中的应用程序提供支持,我们可以将文件上传到 Google Drive 或毫无问题地删除它们,当我们下载文件时,它看起来像httpResponseCode 是正确的 200 和 responseHeader 也是正确的,但 responseBody 是空的。

我将 Google Drive Server 的响应放在这里,以防有人知道。谢谢

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

0 回答 0