簡體   English   中英

有沒有辦法通過 Google API PHP SDK 在 Google Drive 的特定文件夾中創建 Google 文檔?

[英]Is there a way to create Google document in specific folder of Google Drive through Google API PHP SDK?

我已經檢查了每個用戶或組的更新權限,但在我的情況下似乎不可行,因為將從應用程序創建文檔的用戶不會手動添加。 有沒有辦法指定將與每個插入請求一起使用的文件夾(除了 Google Drive 中的根目錄)以將文檔放入其中?

您需要將要在其中創建的文件的目錄的文件夾 ID 設置為元數據中的父級。

 $service = new Google_DriveService($client);
  // Create the file on your Google Drive
  $fileMetadata = new Google_Service_Drive_DriveFile(array(
    'name' => 'My file',
    'parents' => ['FILEIDOFFOLDER']));
  $content = file_get_contents($target_file);
  $mimeType=mime_content_type($target_file);
  $file = $driveService->files->create($fileMetadata, array(
    'data' => $content,
    'mimeType' => $mimeType,
    'fields' => 'id'));
  printf("File ID: %s\n", $file->id);

暫無
暫無

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

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