下午好!我正在尝试下载该文件。我的脚本:
function GetFile($service, $fileId) {
$fileVars = null;
try {
$file = $service->files->get($fileId);
$fileVars = get_object_vars($file);
$downloadUrl = $file->getDownloadUrl();
error_log('Download URL file from Drive: ' . $downloadUrl);
if ($downloadUrl) {
$request = new Google_Http_Request($downloadUrl, 'GET', null, null);
$httpRequest = Google_Client::$io->authenticatedRequest($request);
error_log(print_r($httpRequest, 1));
if ($httpRequest->getResponseHttpCode() == 200) {
$content = $httpRequest->getResponseBody();
$fileVars['content'] = $content?($content):'';
} else {
return null;
}
} else {
return null;
}
} catch (apiServiceException $e) {
error_log('Error retrieving file from Drive: ' . $e->getMessage());
throw $e;
}
return json_encode($fileVars);
}
$requestedFile = GetFile($service,$data[0]['id']);
我推断致命错误:无法访问私有属性Google_Client::$io
告诉我,我犯了什么错?提前感谢,抱歉英语不好!
这适用于
$SignhttpRequest = $client->getAuth()->sign($request);
$httpRequest = $client->getIo()->makeRequest($SignhttpRequest);
使用
$httpRequest = $client->getAuth()->authenticatedRequest($request);
而不是
$httpRequest = Google_Client::$io->authenticatedRequest($request);
参见google_Auth_Abstract:类的google-api-php-client/src/google/Auth/Abstract.php中的注释
一个实用函数,它首先调用$this->auth->sign($request),然后对已签名的请求执行makeRequest()。
请参阅谷歌的迁移指南"从0.6.*迁移到1.0.0"部分的"成员可访问性的变化"one_answers"authenticatedRequest的新家"。