【问题标题】:How to access google shared drive data with php如何使用 php 访问 google 共享驱动器数据
【发布时间】:2020-02-17 22:55:51
【问题描述】:

我的所有文件和文件夹都位于名为“Z”的共享驱动器中。我正在使用 google drive api 列出共享驱动器的所有文件和文件夹,但它返回给我空数组。有权限问题吗

$parentId = 'shareddriveid';
$queryString = "trashed = false and '$parentId' in parents";
$parameters = ['q' => $queryString,'pageSize' => 1000,0,'fields' => 'nextPageToken, files(id, name, fileExtension, fullFileExtension, kind, mimeType, createdTime, modifiedTime, iconLink, webViewLink, webContentLink, parents)'];
$f =$this->drive->files->listFiles($parameters);
dd($f);

【问题讨论】:

  • 如果您只搜索名为 z 的驱动器会发生什么?没有 shareddriveid

标签: php google-drive-api


【解决方案1】:

您可以使用以下代码在 PHP 上获取共享驱动器的文件:

// Print the names and IDs for up to 10 files.
$optParams = array(
    'corpora' => 'drive',
    'driveId' => 'your-shared-drive-id',
    'includeItemsFromAllDrives' => true,
    'pageSize' => 10,
    'supportsAllDrives' => true,
    'fields' => 'nextPageToken, files(id, name)'
);
$results = $service->files->listFiles($optParams);

// print results
foreach ($results->getFiles() as $file){
    printf("%s (%s)\n", $file->getName(), $file->getId());
}

正如Files: list 端点所述,您还必须设置 corporaincludeItemsFromAllDrivessupportsAllDrives 参数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-11-29
    • 2021-10-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多