用于PHP1.0.0下载的Google API客户端库不工作

用于PHP1.0.0下载的Google API客户端库不工作,php,google-api-php-client,Php,Google Api Php Client,使用版本0.6从Google Drive下载文件失败后,我尝试将以下函数转换为使用Google API Client Library for PHP的1.0.0 alpha。我特别不确定的一行是调用getAuth()的那一行。它返回一个具有空http代码响应的对象。我已将答复包括在下面。谁能告诉我我做错了什么 顺便说一句,$service对象(授权的结果)很好,因为我使用它可以毫无问题地获取文件列表 function GetFile($service, $fileId) { $fileVa

使用版本0.6从Google Drive下载文件失败后,我尝试将以下函数转换为使用Google API Client Library for PHP的1.0.0 alpha。我特别不确定的一行是调用getAuth()的那一行。它返回一个具有空http代码响应的对象。我已将答复包括在下面。谁能告诉我我做错了什么

顺便说一句,$service对象(授权的结果)很好,因为我使用它可以毫无问题地获取文件列表

function GetFile($service, $fileId) {
   $fileVars = null;
   try {
      $file = $service->files->get($fileId);
      $fileVars = get_object_vars($file);
      $downloadUrl = $file->getDownloadUrl();

      if ($downloadUrl) {
         $client = $service->getClient();
         $request = new Google_Http_Request($client, $downloadUrl, 'GET', null, null);
         $httpRequest = $client->getAuth()->sign($request);
         drupal_set_message(t("Google_Http_Request: <pre>@status</pre>", array('@status' => print_r($httpRequest, TRUE))));
         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) {
      error_log('Error retrieving file from Drive: ' . $e->getMessage());
      throw $e;
   }
   return json_encode($fileVars);
}

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

    [baseUrl:protected] => https://doc-10-50-docs.googleusercontent.com/docs/securesc/apic76cj8gku48a9ogarn9khpku0s46q/8pk7jcqiirj9bu21a9u2mqa6lmo1887p/1386864000000/08295678552528470768/15372451357194678536/0B6ahcE1NPpIaNE1wRU9TbW1LVU0
    [queryParams:protected] => Array
        (
            [h] => 16653014193614665626
            [e] => download
            [gd] => true
        )

    [requestMethod:protected] => GET
    [requestHeaders:protected] => Array
        (
            [authorization] => Bearer ya29.1.AADtN_V-6HHMTghP6EFc3DD1Ktf3wFyQtxscciNyyJzlu36YPG_oC7iX565RctWgCl9MQ4tB1Q
        )

    [postBody:protected] => 
    [userAgent:protected] =>  google-api-php-client/1.0.1-alpha
    [responseHttpCode:protected] => 
    [responseHeaders:protected] => 
    [responseBody:protected] => 
    [expectedClass:protected] => 
    [client:protected] => Google_Client Object
        (
            [auth:Google_Client:private] => Google_Auth_OAuth2 Object
                (
                    [assertionCredentials:Google_Auth_OAuth2:private] => 
                    [state:Google_Auth_OAuth2:private] => 
                    [token:Google_Auth_OAuth2:private] => Array
                        (
                            [access_token] => xxx
                            [token_type] => Bearer
                            [expires_in] => 3552
                            [created] => 1386868612
                        )

                    [client:Google_Auth_OAuth2:private] => Google_Client Object
 *RECURSION*
                )

            [io:Google_Client:private] => Google_IO_Stream Object
                (
                    [client:protected] => Google_Client Object
 *RECURSION*
                )

            [cache:Google_Client:private] => 
            [config:Google_Client:private] => Google_Config Object
                (
                    [configuration:Google_Config:private] => Array
                        (
                            [application_name] => 
                            [auth_class] => Google_Auth_OAuth2
                            [io_class] => Google_IO_Stream
                            [cache_class] => Google_Cache_File
                            [base_path] => https://www.googleapis.com
                            [classes] => Array
                                (
                                    [Google_Auth_OAuth2] => Array
                                        (
                                            [client_id] => xxx
                                            [client_secret] => xxx
                                            [redirect_uri] => http://flashum.com/goauth/authenticate
                                            [developer_key] => 
                                            [access_type] => online
                                            [approval_prompt] => auto
                                            [request_visible_actions] => 
                                            [federated_signon_certs_url] => https://www.googleapis.com/oauth2/v1/certs
                                        )

                                    [Google_Cache_File] => Array
                                        (
                                            [directory] => C:\Users\CDAVID~1\AppData\Local\Temp/Google_Client
                                        )

                                )

                            [services] => Array
                                (
                                )

                        )

                )

            [deferExecution:Google_Client:private] => 
            [availableScopes:protected] => Array
                (
                    [drive] => Array
                        (
                            [0] => https://www.googleapis.com/auth/drive
                            [1] => https://www.googleapis.com/auth/drive.apps.readonly
                            [2] => https://www.googleapis.com/auth/drive.readonly
                            [3] => https://www.googleapis.com/auth/drive.file
                            [4] => https://www.googleapis.com/auth/drive.scripts
                            [5] => https://www.googleapis.com/auth/drive.metadata.readonly
                            [6] => https://www.googleapis.com/auth/drive.appdata
                        )

                )

            [requestedScopes:protected] => Array
                (
                    [0] => https://www.googleapis.com/auth/drive
                )

            [services:protected] => Array
                (
                )

            [authenticated:Google_Client:private] => 
        )

    [accessKey] => 
    [basePath:Google_Http_Request:private] => https://www.googleapis.com
)
函数GetFile($service,$fileId){
$fileVars=null;
试一试{
$file=$service->files->get($fileId);
$fileVars=获取对象变量($file);
$downloadUrl=$file->getDownloadUrl();
如果($downloadUrl){
$client=$service->getClient();
$request=新的Google_Http_请求($client,$downloadUrl,'GET',null,null);
$httpRequest=$client->getAuth()->签名($request);
drupal_set_消息(t(“Google_Http_请求:@status”,数组('@status'=>print_r($httpRequest,TRUE)));
function downloadFiles($downloadUrl) {

    //        $default_opts = array(
    //            'http' => array(
    //                'follow_location' => 1
    //            )
    //        );
    //
    //        stream_context_set_default($default_opts);

            $request = new Google_Http_Request($this->getGoogleClient(), $downloadUrl, 'GET', null, null);
            $SignhttpRequest = $this->getGoogleClient()->getAuth()->sign($request);
            $httpRequest = $this->getGoogleClient()->getIo()->makeRequest($SignhttpRequest);

            if ($httpRequest->getResponseHttpCode() == 200) {
                return array($httpRequest->getResponseHeaders(), $httpRequest->getResponseBody());
            } else {
                return null;
            }
        }
错误日志(打印($httpRequest,1));
如果($httpRequest->getResponseHttpCode()==200){
$content=$httpRequest->getResponseBody();
$fileVars['content']=$content?($content):'';
}否则{
//发生了一个错误。
返回null;
}
}否则{
//该文件在驱动器上未存储任何内容。
返回null;
}
}捕获(apiServiceException$e){
错误日志('从驱动器检索文件时出错:'。$e->getMessage());
扔$e;
}
返回json_encode($fileVars);
}
Google\u Http\u请求对象
(
[batchHeaders:Google\u Http\u请求:private]=>数组
function downloadFiles($downloadUrl) {

    //        $default_opts = array(
    //            'http' => array(
    //                'follow_location' => 1
    //            )
    //        );
    //
    //        stream_context_set_default($default_opts);

            $request = new Google_Http_Request($this->getGoogleClient(), $downloadUrl, 'GET', null, null);
            $SignhttpRequest = $this->getGoogleClient()->getAuth()->sign($request);
            $httpRequest = $this->getGoogleClient()->getIo()->makeRequest($SignhttpRequest);

            if ($httpRequest->getResponseHttpCode() == 200) {
                return array($httpRequest->getResponseHeaders(), $httpRequest->getResponseBody());
            } else {
                return null;
            }
        }
(
[内容类型]=>应用程序/http
[内容传输编码]=>二进制
[MIME版本]=>1.0
)
[baseUrl:受保护]=>https://doc-10-50-docs.googleusercontent.com/docs/securesc/apic76cj8gku48a9ogarn9khpku0s46q/8pk7jcqiirj9bu21a9u2mqa6lmo1887p/1386864000000/08295678552528470768/15372451357194678536/0B6ahcE1NPpIaNE1wRU9TbW1LVU0
[查询参数:受保护]=>数组
(
[h] =>16653014193614665626
[e] =>下载
[gd]=>正确
)
[requestMethod:protected]=>GET
[requestHeaders:受保护]=>阵列
(
[授权]=>承载ya29.1.AADtN_V-6HHMTGHP6EFC3DD1KTF3WFYQTXSCCINYJZLU36YPG_oC7iX565RctWgCl9MQ4tB1Q
)
[正文:受保护]=>
[userAgent:protected]=>google api php客户端/1.0.1-alpha
[响应HttpCode:受保护]=>
[负责人:受保护]=>
[响应主体:受保护]=>
[expectedClass:受保护]=>
[客户端:受保护]=>Google_客户端对象
(
[auth:Google\u Client:private]=>Google\u auth\u OAuth2对象
(
[assertionCredentials:Google\u Auth\u OAuth2:private]=>
[状态:Google\u Auth\u OAuth2:private]=>
[令牌:Google\u Auth\u OAuth2:private]=>数组
(
[访问令牌]=>xxx
[令牌类型]=>承载
[expires_in]=>3552
[已创建]=>13868612
)
[client:Google\u Auth\u OAuth2:private]=>Google\u客户端对象
*递归*
)
[io:Google\u客户端:私有]=>Google\u io\u流对象
(
[客户端:受保护]=>Google_客户端对象
*递归*
)
[cache:Google\u客户端:private]=>
[config:Google\u Client:private]=>Google\u配置对象
(
[配置:Google\u配置:private]=>数组
(
[应用程序名称]=>
[auth_class]=>Google_auth_OAuth2
[io_类]=>Google_io_流
[cache\u class]=>Google\u cache\u文件
[基本路径]=>https://www.googleapis.com
[类]=>数组
(
[Google_Auth_OAuth2]=>数组
(
[客户id]=>xxx
[客户机密]=>xxx
[重定向\u uri]=>http://flashum.com/goauth/authenticate
[开发者密钥]=>
[访问类型]=>联机
[批准提示]=>自动
[请求\u可见\u操作]=>
[federated\u signon\u certs\u url]=>https://www.googleapis.com/oauth2/v1/certs
)
[谷歌缓存文件]=>阵列
(
[目录]=>C:\Users\CDAVID~1\AppData\Local\Temp/Google\u客户端
)
)
[服务]=>阵列
(
)
)
)
[deferExecution:Google\u客户端:private]=>
[可用范围:受保护]=>阵列
(
[驱动器]=>阵列
(
[0] => https://www.googleapis.com/auth/drive
[1] => https://www.googleapis.com/auth/drive.apps.readonly
[2] => https://www.googleapis.com/auth/drive.readonl