【问题标题】:download google drives files google drive api php v2下载 google drive 文件 google drive api php v2
【发布时间】:2018-08-29 02:42:36
【问题描述】:

我正在使用这个功能从谷歌驱动器下载文件,它工作正常但它没有下载任何东西,我还需要做什么吗?这是网站上的示例,并且正在与我一起工作,我在 $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;
}

【问题讨论】:

    标签: php google-api google-drive-api google-api-php-client


    【解决方案1】:

    如果$httpRequest->getResponseBody(); 正在打印数据,那么为什么不将其保存到文件中呢?

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

    Drive v3

    Google Drive v3 已经发布两年多了,您应该考虑更新您的应用程序。

    你应该考虑关注谷歌下载教程manage downloads

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

    【讨论】:

    • 我看到了,但我没有这个 getBody,所以我使用了这个也在文档中的替代模式
    • 如果你没有getBody,那么你需要更新你正在使用旧版本的客户端库或者这里有更多示例examples
    • 有什么理由不想使用新版Google drive api?
    • 因为我的PHP版本有限,我的版本是5.3,我不能换到5.4(新版本的必要版本),因为我的网站是5.3成型的。
    猜你喜欢
    • 1970-01-01
    • 2015-11-17
    • 1970-01-01
    • 2017-11-02
    • 2015-02-06
    • 2022-01-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多