[英]How can I create a folder within a Team Drive with the Google API?
[英]Move a folder into a Team Drive using Google Drive API
我正在將我的雲端硬盤遷移到團隊雲端硬盤,並且我有幾千個文件夾要移動,每個文件夾都放入自己的雲端硬盤。 我有一些使用google/apiclient:2.7
的 php 代碼可以使用 Google Drive API 來創建驅動器。 我現在需要移動文件夾,並且在這樣做時遇到錯誤。
我的代碼使用 OAuth 對具有適當權限並能夠使用 Google UI 遷移文件夾的用戶進行身份驗證。 當我使用 php 代碼將文件移動到團隊驅動器時,它移動成功。 當我嘗試對文件夾執行此操作時,我收到一條錯誤消息。
代碼:
//$files is an array where the values are the google id's
$id = $files['File adI3O'];
$parentId = $files['Drive'];
$google_file = new Google_Service_Drive_DriveFile();
//The parents field is not directly writable in update requests. Use the addParents and removeParents parameters instead.
//$google_file->setParents([$parentId]);
/** @var Google_Service_Drive $service */
$response = $service->files->update($id, $google_file, $service->optParams([
'supportsAllDrives' => true,
'addParents' => $parentId,
//'useDomainAdminAccess' => true,//(update) unknown parameter: 'useDomainAdminAccess'
]));
(我的代碼中沒有 removeParents 參數。我在不使用 removeParents 參數的情況下成功移動了文件,因此一定不需要它。)
將 $id 設置為$files['Folder 69daL']
時出現錯誤消息:
Google_Service_Exception: {
"error": {
"errors": [
{
"domain": "global",
"reason": "teamDrivesFolderMoveInNotSupported",
"message": "Moving folders into shared drives is not supported."
}
],
"code": 403,
"message": "Moving folders into shared drives is not supported."
}
}
谷歌文檔表明,通過適當的權限,可以將文件夾移動到共享驅動器中。 如何使用 Google Drive API 完成?
我認為,就像錯誤消息所說的那樣,它不受支持。 文檔說這是可能的,但沒有說 API 可以做到這一點。 歷史上,Google API 並不總是公開用戶可以執行的所有操作。 如果你想用 API 來做這件事,你可能會不走運。
https://developers.google.com/drive/api/v3/about-shareddrives
API 文檔根本沒有提到將文件移動到共享驅動器中; 僅管理共享驅動器的權限。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.