Google Drive API downloadFile getIo Error

I want to create a gDrive app. I can get downloadUrl (for example, a string "https://doc-0k-68-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/21kfelc8h3l1qvkgskqacnee2pqjt5es/1343484000000/14678698184812381901/14678698184812381901/0B95t2gVGbZ61Sk0yNlY5TTZObUU?h=16653014193614665626&e=download&gd=true "(length = 251))

But I can not download this link. I suppose there should be some kind of out.

I try these functions, I take here

function downloadFile($service, $file) { $downloadUrl = $file->getDownloadUrl(); if ($downloadUrl) { $request = new apiHttpRequest($downloadUrl, 'GET', null, null); $httpRequest = $service->getIo()->authenticatedRequest($request); if ($httpRequest->getResponseHttpCode() == 200) { return $httpRequest->getResponseBody(); } else { // An error occurred. return null; } } else { // The file doesn't have any content stored on Drive. return null; } } 

I accept a mistake

Calling the undefined apiDriveService :: getIo () method in ...

Please help me. I can’t find anything.

 object(apiHttpRequest)[18] protected 'url' => string 'https://doc-0k-68-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/900384ep39btqvj6j91ssm11lvom8r09/1343635200000/14678698184812381901/14678698184812381901/0B95t2gVGbZ61Sk0yNlY5TTZObUU?h=16653014193614665626&e=download&gd=true&key=AIzaSyA1qi-3-tqpyzxAXhy5c9_EkVGFNsRZ9Fw' (length=295) protected 'requestMethod' => string 'GET' (length=3) protected 'requestHeaders' => array (size=1) 'authorization' => string 'Bearer ya29.AHES6ZTgpamuF6g35HuLj2PW_KH06yZhLLNdNLF_MgaiFGLp' (length=60) protected 'postBody' => null protected 'userAgent' => string 'Tahribat google-api-php-client/0.5.0' (length=36) protected 'responseHttpCode' => int 404 protected 'responseHeaders' => array (size=10) 'server' => string 'HTTP Upload Server Built on Jul 25 2012 10:54:42 (1343238882)' (length=61) 'access-control-allow-origin' => string '*' (length=1) 'access-control-allow-credentials' => string 'false' (length=5) 'access-control-allow-headers' => string 'authorization' (length=13) 'access-control-allow-methods' => string 'GET,OPTIONS' (length=11) 'date' => string 'Mon, 30 Jul 2012 08:01:31 GMT' (length=29) 'expires' => string 'Mon, 30 Jul 2012 08:01:31 GMT' (length=29) 'cache-control' => string 'private, max-age=0' (length=18) 'content-length' => string '0' (length=1) 'content-type' => string 'text/html; charset=UTF-8' (length=24) protected 'responseBody' => boolean false public 'accessKey' => null https://doc-0k-68-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/900384ep39btqvj6j91ssm11lvom8r09/1343635200000/14678698184812381901/14678698184812381901/0B95t2gVGbZ61Sk0yNlY5TTZObUU?h=16653014193614665626&e=download&gd=true&key=AIzaSyA1qi- object(apiHttpRequest)[18] protected 'url' => string 'https://doc-0k-68-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/900384ep39btqvj6j91ssm11lvom8r09/1343635200000/14678698184812381901/14678698184812381901/0B95t2gVGbZ61Sk0yNlY5TTZObUU?h=16653014193614665626&e=download&gd=true&key=AIzaSyA1qi-3-tqpyzxAXhy5c9_EkVGFNsRZ9Fw' (length=295) protected 'requestMethod' => string 'GET' (length=3) protected 'requestHeaders' => array (size=1) 'authorization' => string 'Bearer ya29.AHES6ZTgpamuF6g35HuLj2PW_KH06yZhLLNdNLF_MgaiFGLp' (length=60) protected 'postBody' => null protected 'userAgent' => string 'Tahribat google-api-php-client/0.5.0' (length=36) protected 'responseHttpCode' => int 404 protected 'responseHeaders' => array (size=10) 'server' => string 'HTTP Upload Server Built on Jul 25 2012 10:54:42 (1343238882)' (length=61) 'access-control-allow-origin' => string '*' (length=1) 'access-control-allow-credentials' => string 'false' (length=5) 'access-control-allow-headers' => string 'authorization' (length=13) 'access-control-allow-methods' => string 'GET,OPTIONS' (length=11) 'date' => string 'Mon, 30 Jul 2012 08:01:31 GMT' (length=29) 'expires' => string 'Mon, 30 Jul 2012 08:01:31 GMT' (length=29) 'cache-control' => string 'private, max-age=0' (length=18) 'content-length' => string '0' (length=1) 'content-type' => string 'text/html; charset=UTF-8' (length=24) protected 'responseBody' => boolean false public 'accessKey' => null 

///////

 object(DriveFile)[15] public 'mimeType' => string 'application/rar' (length=15) public 'thumbnailLink' => null protected '__labelsType' => string 'DriveFileLabels' (length=15) protected '__labelsDataType' => string '' (length=0) public 'labels' => object(DriveFileLabels)[16] public 'restricted' => boolean false public 'hidden' => boolean false public 'viewed' => boolean false public 'starred' => boolean false public 'trashed' => boolean false protected '__indexableTextType' => string 'DriveFileIndexableText' (length=22) protected '__indexableTextDataType' => string '' (length=0) public 'indexableText' => null public 'etag' => string '"WtRjAPZWbDA7_fkFjc5ojsEvE7I/MTM0MzM1NDI2OTYwMA"' (length=48) public 'lastModifyingUserName' => string 'Pskptbt6' (length=8) public 'writersCanShare' => boolean true public 'id' => string '0By790Jqkq9pLRDRuUFZ3UWVxdGs' (length=28) public 'title' => string '1caec72e95949a693dc0e95eeaeb2a9e.rar' (length=36) public 'ownerNames' => array (size=1) 0 => string 'Pskptbt6' (length=8) public 'sharedWithMeDate' => null public 'lastViewedByMeDate' => null protected '__parentsType' => string 'ParentReference' (length=15) protected '__parentsDataType' => string 'array' (length=5) public 'parents' => array (size=0) empty public 'exportLinks' => null public 'originalFilename' => string 'Web Elements.rar' (length=16) public 'description' => null public 'editable' => boolean false public 'kind' => string 'drive#file' (length=10) public 'quotaBytesUsed' => string '30249130' (length=8) public 'fileSize' => string '30249130' (length=8) public 'createdDate' => string '2012-07-27T01:55:50.169Z' (length=24) public 'md5Checksum' => string '595182e10bcc986cc8dcc41a6e945019' (length=32) public 'embedLink' => null public 'alternateLink' => string 'https://docs.google.com/file/d/0By790Jqkq9pLRDRuUFZ3UWVxdGs/edit' (length=64) public 'permissionsLink' => null public 'modifiedByMeDate' => null public 'downloadUrl' => string 'https://doc-04-5s-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/t1ucp1ub6sdcgk7hdatj1it5m5ntoodh/1343635200000/13117762293604295629/14678698184812381901/0By790Jqkq9pLRDRuUFZ3UWVxdGs?h=16653014193614665626&e=download&gd=true' (length=251) protected '__userPermissionType' => string 'Permission' (length=10) protected '__userPermissionDataType' => string '' (length=0) public 'userPermission' => object(Permission)[17] public 'withLink' => null public 'kind' => string 'drive#permission' (length=16) public 'name' => null public 'value' => null public 'id' => string 'me' (length=2) public 'authKey' => null public 'etag' => string '"WtRjAPZWbDA7_fkFjc5ojsEvE7I/dLmoyrW_nZG7qLX6EhuNvVbQIq0"' (length=57) public 'role' => string 'reader' (length=6) public 'photoLink' => null public 'type' => string 'user' (length=4) public 'additionalRoles' => null public 'selfLink' => string 'https://www.googleapis.com/drive/v2/files/0By790Jqkq9pLRDRuUFZ3UWVxdGs/permissions/me' (length=85) public 'fileExtension' => string 'rar' (length=3) public 'selfLink' => string 'https://www.googleapis.com/drive/v2/files/0By790Jqkq9pLRDRuUFZ3UWVxdGs' (length=70) public 'modifiedDate' => string '2012-07-27T01:57:49.600Z' (length=24) public 'webContentLink' => string 'https://docs.google.com/uc?id=0By790Jqkq9pLRDRuUFZ3UWVxdGs&export=download' (length=74) https://doc-04-5s-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/t1ucp1ub6sdcgk7hdatj1it5m5ntoodh/1343635200000/13117762293604295629/14678698184812381901/0By790Jqkq9pLRDRuUFZ3UWVxdGs?h=16653014193614665626&e=download&gd=true' (length object(DriveFile)[15] public 'mimeType' => string 'application/rar' (length=15) public 'thumbnailLink' => null protected '__labelsType' => string 'DriveFileLabels' (length=15) protected '__labelsDataType' => string '' (length=0) public 'labels' => object(DriveFileLabels)[16] public 'restricted' => boolean false public 'hidden' => boolean false public 'viewed' => boolean false public 'starred' => boolean false public 'trashed' => boolean false protected '__indexableTextType' => string 'DriveFileIndexableText' (length=22) protected '__indexableTextDataType' => string '' (length=0) public 'indexableText' => null public 'etag' => string '"WtRjAPZWbDA7_fkFjc5ojsEvE7I/MTM0MzM1NDI2OTYwMA"' (length=48) public 'lastModifyingUserName' => string 'Pskptbt6' (length=8) public 'writersCanShare' => boolean true public 'id' => string '0By790Jqkq9pLRDRuUFZ3UWVxdGs' (length=28) public 'title' => string '1caec72e95949a693dc0e95eeaeb2a9e.rar' (length=36) public 'ownerNames' => array (size=1) 0 => string 'Pskptbt6' (length=8) public 'sharedWithMeDate' => null public 'lastViewedByMeDate' => null protected '__parentsType' => string 'ParentReference' (length=15) protected '__parentsDataType' => string 'array' (length=5) public 'parents' => array (size=0) empty public 'exportLinks' => null public 'originalFilename' => string 'Web Elements.rar' (length=16) public 'description' => null public 'editable' => boolean false public 'kind' => string 'drive#file' (length=10) public 'quotaBytesUsed' => string '30249130' (length=8) public 'fileSize' => string '30249130' (length=8) public 'createdDate' => string '2012-07-27T01:55:50.169Z' (length=24) public 'md5Checksum' => string '595182e10bcc986cc8dcc41a6e945019' (length=32) public 'embedLink' => null public 'alternateLink' => string 'https://docs.google.com/file/d/0By790Jqkq9pLRDRuUFZ3UWVxdGs/edit' (length=64) public 'permissionsLink' => null public 'modifiedByMeDate' => null public 'downloadUrl' => string 'https://doc-04-5s-docs.googleusercontent.com/docs/securesc/gf6salc3nfs5me1dnqgnp4crl90gg593/t1ucp1ub6sdcgk7hdatj1it5m5ntoodh/1343635200000/13117762293604295629/14678698184812381901/0By790Jqkq9pLRDRuUFZ3UWVxdGs?h=16653014193614665626&e=download&gd=true' (length=251) protected '__userPermissionType' => string 'Permission' (length=10) protected '__userPermissionDataType' => string '' (length=0) public 'userPermission' => object(Permission)[17] public 'withLink' => null public 'kind' => string 'drive#permission' (length=16) public 'name' => null public 'value' => null public 'id' => string 'me' (length=2) public 'authKey' => null public 'etag' => string '"WtRjAPZWbDA7_fkFjc5ojsEvE7I/dLmoyrW_nZG7qLX6EhuNvVbQIq0"' (length=57) public 'role' => string 'reader' (length=6) public 'photoLink' => null public 'type' => string 'user' (length=4) public 'additionalRoles' => null public 'selfLink' => string 'https://www.googleapis.com/drive/v2/files/0By790Jqkq9pLRDRuUFZ3UWVxdGs/permissions/me' (length=85) public 'fileExtension' => string 'rar' (length=3) public 'selfLink' => string 'https://www.googleapis.com/drive/v2/files/0By790Jqkq9pLRDRuUFZ3UWVxdGs' (length=70) public 'modifiedDate' => string '2012-07-27T01:57:49.600Z' (length=24) public 'webContentLink' => string 'https://docs.google.com/uc?id=0By790Jqkq9pLRDRuUFZ3UWVxdGs&export=download' (length=74) 

In fact, I just like this site.

http://www.gdriveurl.com/

but, I’m just automatically creating every link on my site.

+7
source share
3 answers

I installed the latest PHP client library and none of the proposed changes above work.

Source

  $httpRequest = $service->getIo()->authenticatedRequest($request); Fatal error: Call to undefined method Google_Service_Drive::getIo() 

First proposed change:

 $httpRequest = apiClient::$io->authenticatedRequest($request); Fatal error: Class 'apiClient' not found in ...../Drive/auth.php 

Second proposed change:

 $httpRequest = Google_Client::$io->authenticatedRequest($request); Fatal error: Cannot access private property Google_Client::$io in .../Drive/auth.php 

I found "authenticatedRequest ($ request)"; in-src / Google / Auth / OAuth2.php

  public function authenticatedRequest(Google_Http_Request $request) { $request = $this->sign($request); return $this->client->getIo()->makeRequest($request); } 

so I change the call to:

  $httpRequest = Google_Auth_OAuth2::authenticatedRequest($request); 

but it returns an error:

Fatal error: using $ this if not in object context

Finally found a solution, and here is the complete code:

 function downloadFile($service, $downloadUrl,$client) { if ($downloadUrl) { $request = new Google_Http_Request($downloadUrl, 'GET', null, null); $SignhttpRequest = $client->getAuth()->sign($request); $httpRequest = $client->getIo()->makeRequest($SignhttpRequest); if ($httpRequest->getResponseHttpCode() == 200) { return $httpRequest->getResponseBody(); } else { // An error occurred. return null; } } else { // The file doesn't have any content stored on Drive. return null; } } 
+8
source

Change this line:

  $httpRequest = $service->getIo()->authenticatedRequest($request); 

by:

  $httpRequest = apiClient::$io->authenticatedRequest($request); 

I had an error, and after changing the line, I had no more problems.

Service

$ seems to refer to apiClient, not apiDriveService.

+1
source
 $request = new Google_HttpRequest($downloadUrl, 'GET', null, null); $httpRequest = Google_Client::$io->authenticatedRequest($request); 

for the new google-api-php-client-0.6.0.tar.gz library

0
source

All Articles