簡體   English   中英

下載谷歌驅動器文件谷歌驅動器api php v2

[英]download google drives files google drive api php v2

我正在使用此功能從谷歌驅動器下載文件,它工作正常但沒有下載任何東西,我還需要做些什么嗎? 這是網站上的示例,它與我一起工作,我在 $httpRequest->getResponseBody(); 中寫了一個回聲; 並打印正確,但我要下載這個做什么?

$downloadUrl = $file->getDownloadUrl(); 

if ($downloadUrl) {
    $request = new Google_Http_Request($downloadUrl, 'GET', null, null);
    $httpRequest = $service->getClient()->getAuth()->authenticatedRequest($request);
    if ($httpRequest->getResponseHttpCode() == 200) {
       return $httpRequest->getResponseBody();
    } else {
      echo 'An error occurred';
      exit;
      return null;
    }
} else {
     echo'The file doesnt have any content stored on Drive';
     exit;
      return null;
}

如果$httpRequest->getResponseBody(); 正在打印數據,那么為什么不將其保存到文件中呢?

$data = $httpRequest->getResponseBody();
file_put_contents("test.txt", data);

驅動器 v3

Google Drive v3 已經發布兩年多了,您應該考慮更新您的應用程序。

您應該考慮遵循 Googles 下載教程管理下載

 $fileId = '0BwwA4oUTeiV1UVNwOHItT0xfa2M';
 $response = $driveService->files->get($fileId, array(
'alt' => 'media'));
 $content = $response->getBody()->getContents();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM