管理共用雲端硬碟

本指南包含使用 Google Drive API 管理共用雲端硬碟的相關工作,例如建立共用雲端硬碟,以及管理成員和權限。

如要指定要在回應中傳回的欄位,可以使用 drives 資源的任何方法,設定 fields system 參數。如未指定 fields 參數,伺服器會傳回方法專屬的一組預設欄位。舉例來說,list 方法只會傳回每個共用雲端硬碟的 kindidname 欄位。詳情請參閱「傳回特定欄位」。

如要進一步瞭解共用雲端硬碟資料夾限制,請參閱「共用雲端硬碟資料夾限制」。

建立共用雲端硬碟

如要建立共用雲端硬碟,請使用 drives 資源的 create 方法搭配 requestId 參數。

requestId 參數會識別共用雲端硬碟的邏輯嘗試,以進行等冪建立作業。如果要求逾時或傳回不確定的後端錯誤,可以重複發出相同要求,不會建立重複項目。要求requestId和主體必須保持不變。

以下程式碼範例說明如何建立共用雲端硬碟:

Java

drive/snippets/drive_v3/src/main/java/CreateDrive.java
import com.google.api.client.googleapis.json.GoogleJsonResponseException;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.Drive;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.Arrays;
import java.util.UUID;

/* class to demonstrate use-case of Drive's create drive. */
public class CreateDrive {

  /**
   * Create a drive.
   *
   * @return Newly created drive id.
   * @throws IOException if service account credentials file not found.
   */
  public static String createDrive() throws IOException {
        /*Load pre-authorized user credentials from the environment.
        TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application.*/
    GoogleCredentials credentials =
        GoogleCredentials.getApplicationDefault().createScoped(Arrays.asList(DriveScopes.DRIVE));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Build a new authorized API client service.
    com.google.api.services.drive.Drive service =
        new com.google.api.services.drive.Drive.Builder(new NetHttpTransport(),
            GsonFactory.getDefaultInstance(),
            requestInitializer)
            .setApplicationName("Drive samples")
            .build();

    Drive driveMetadata = new Drive();
    driveMetadata.setName("Project Resources");
    String requestId = UUID.randomUUID().toString();
    try {
      Drive drive = service.drives().create(requestId,
              driveMetadata)
          .execute();
      System.out.println("Drive ID: " + drive.getId());

      return drive.getId();
    } catch (GoogleJsonResponseException e) {
      // TODO(developer) - handle error appropriately
      System.err.println("Unable to create drive: " + e.getDetails());
      throw e;
    }
  }
}

Python

drive/snippets/drive-v3/drive_snippet/create_drive.py
import uuid

import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def create_drive():
  """Create a drive.
  Returns:
      Id of the created drive

  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()

  try:
    # create drive api client
    service = build("drive", "v3", credentials=creds)

    drive_metadata = {"name": "Project Resources"}
    request_id = str(uuid.uuid4())
    # pylint: disable=maybe-no-member
    drive = (
        service.drives()
        .create(body=drive_metadata, requestId=request_id, fields="id")
        .execute()
    )
    print(f'Drive ID: {drive.get("id")}')

  except HttpError as error:
    print(f"An error occurred: {error}")
    drive = None

  return drive.get("id")


if __name__ == "__main__":
  create_drive()

Node.js

drive/snippets/drive_v3/drive_snippets/create_drive.js
/**
 * Create a drive.
 * */
async function createDrive() {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');
  const uuid = require('uuid');

  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/drive',
  });
  const service = google.drive({version: 'v3', auth});

  const driveMetadata = {
    name: 'Project resources',
  };
  const requestId = uuid.v4();
  try {
    const Drive = await service.drives.create({
      resource: driveMetadata,
      requestId: requestId,
      fields: 'id',
    });
    console.log('Drive Id:', Drive.data.id);
    return Drive.data.id;
  } catch (err) {
    // TODO(developer) - Handle error
    throw err;
  }
}

PHP

drive/snippets/drive_v3/src/DriveCreateDrive.php
<?php
use Google\Client;
use Google\Service\Drive;
use Ramsey\Uuid\Uuid;
function createDrive()
{
    try {
        $client = new Client();
        $client->useApplicationDefaultCredentials();
        $client->addScope(Drive::DRIVE);
        $driveService = new Drive($client);

        $driveMetadata = new Drive\Drive(array(
                'name' => 'Project Resources'));
        $requestId = Uuid::uuid4()->toString();
        $drive = $driveService->drives->create($requestId, $driveMetadata, array(
                'fields' => 'id'));
        printf("Drive ID: %s\n", $drive->id);
        return $drive->id;
    } catch(Exception $e)  {
        echo "Error Message: ".$e;
    }  

}

.NET

drive/snippets/drive_v3/DriveV3Snippets/CreateDrive.cs
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using Google.Apis.Services;

namespace DriveV3Snippets
{
    // Class to demonstrate use of Drive's create drive.
    public class CreateDrive
    {
        /// <summary>
        /// Create a drive.
        /// </summary>
        /// <returns>newly created drive Id.</returns>
        public static string DriveCreateDrive()
        {
            try
            {
                /* Load pre-authorized user credentials from the environment.
                 TODO(developer) - See https://developers.google.com/identity for
                 guides on implementing OAuth2 for your application. */
                GoogleCredential credential = GoogleCredential.GetApplicationDefault()
                    .CreateScoped(DriveService.Scope.Drive);

                // Create Drive API service.
                var service = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Drive API Snippets"
                });

                var driveMetadata = new Drive()
                {
                    Name = "Project Resources"
                };
                var requestId = Guid.NewGuid().ToString();
                var request = service.Drives.Create(driveMetadata, requestId);
                request.Fields = "id";
                var drive = request.Execute();
                Console.WriteLine("Drive ID: " + drive.Id);
                return drive.Id;
            }
            catch (Exception e)
            {
                // TODO(developer) - handle error appropriately
                if (e is AggregateException)
                {
                    Console.WriteLine("Credential Not found");
                }
                else
                {
                    throw;
                }
            }
            return null;
        }
    }
}

create 方法的呼叫是冪等。

如果共用雲端硬碟是透過先前的要求或重試建立成功,這個方法會傳回 drives 資源的執行個體。有時,例如經過一段時間後,或要求主體已變更,可能會傳回 409 錯誤,指出必須捨棄 requestId

取得共用雲端硬碟

如要取得共用雲端硬碟的中繼資料,請在 drives 資源上使用 get 方法,並搭配 driveId 路徑參數。如果您不知道雲端硬碟 ID,可以使用 list 方法列出所有共用雲端硬碟

get 方法會以 drives 資源的執行個體形式傳回共用雲端硬碟。

如要以網域管理員身分發出要求,請將 useDomainAdminAccess 查詢參數設為 true。詳情請參閱「以網域管理員身分管理共用雲端硬碟」。

列出共用雲端硬碟

如要列出使用者的共用雲端硬碟,請使用 drives 資源的 list 方法。這個方法會傳回共用雲端硬碟清單。

傳遞下列查詢參數,即可自訂共用雲端硬碟的分頁或篩選條件:

  • pageSize:每個頁面傳回的共用雲端硬碟數量上限。

  • pageToken:屬於接收自前一個清單呼叫的網頁權杖。提供此權杖即可擷取後續網頁。

  • q:用於搜尋共用雲端硬碟的查詢字串。詳情請參閱「搜尋共用雲端硬碟」。

  • useDomainAdminAccess:設為 true,即可將要求發給網域管理員,傳回要求者所屬網域的所有共用雲端硬碟。詳情請參閱「以網域管理員身分管理共用雲端硬碟」。

更新共用雲端硬碟

如要更新共用雲端硬碟的中繼資料,請在 drives 資源上使用 update 方法,並提供 driveId 路徑參數。

這個方法會以 drives 資源的執行個體形式傳回共用雲端硬碟。

如要以網域管理員身分發出要求,請將 useDomainAdminAccess 查詢參數設為 true。詳情請參閱「以網域管理員身分管理共用雲端硬碟」。

隱藏及取消隱藏共用雲端硬碟

如要從預設檢視畫面隱藏共用雲端硬碟,請在 drives 資源上使用 hide 方法和 driveId 參數。

隱藏共用雲端硬碟後,雲端硬碟會將共用雲端硬碟資源標示為 hidden=true。隱藏的共用雲端硬碟不會顯示在雲端硬碟使用者介面或傳回的檔案清單中。

如要將共用雲端硬碟還原為預設檢視畫面,請在 drives 資源上使用 driveId 參數的 unhide 方法。

這兩種方法都會以 drives 資源例項的形式傳回共用雲端硬碟。

刪除共用雲端硬碟

如要永久刪除共用雲端硬碟,請在 drives 資源上使用 delete 方法,並搭配 driveId 參數。

刪除共用雲端硬碟前,必須先將所有內容移至垃圾桶或刪除。使用者也必須對共用雲端硬碟資料夾擁有 role=organizer。詳情請參閱「將檔案和資料夾移至垃圾桶或刪除」。

傳遞下列查詢參數,篩選共用雲端硬碟:

  • useDomainAdminAccess:設為 true,即可將要求發給網域管理員,傳回要求者所屬網域的所有共用雲端硬碟。詳情請參閱「以網域管理員身分管理共用雲端硬碟」。

  • allowItemDeletion:設為 true 可刪除共用雲端硬碟中的項目。 只有在 useDomainAdminAccess 也設為 true 時,系統才會支援這項功能。

新增或移除共用雲端硬碟成員

使用 permissions 資源新增或移除共用雲端硬碟成員。

如要新增成員,請在共用雲端硬碟中建立權限。您也可以對共用雲端硬碟中的個別檔案使用權限方法,授予成員額外權限,或允許非成員協作處理特定項目。

如需更多資訊和範例程式碼,請參閱「共用檔案、資料夾和雲端硬碟」。

以網域管理員身分管理共用雲端硬碟

搭配 drivespermissions 資源套用 useDomainAdminAccess 參數,即可管理整個機構的共用雲端硬碟。

使用 useDomainAdminAccess=true 呼叫這些方法的使用者必須具備Drive and Docs 管理員權限。管理員可以搜尋共用雲端硬碟,或更新所屬機構擁有的共用雲端硬碟權限,無論管理員是否為特定共用雲端硬碟的成員,都能執行這些操作。

使用服務帳戶時,您可能必須使用服務帳戶模擬功能,模擬已通過驗證的管理員。 請注意,服務帳戶屬於您的 Google Workspace 網域,與使用者帳戶不同。如果您與整個 Google Workspace 網域共用 Google Workspace 資產 (例如文件或活動),這些資產不會與服務帳戶共用。詳情請參閱服務帳戶總覽

復原沒有主辦人的共用雲端硬碟

下列程式碼範例說明如何復原沒有主辦人的共用雲端硬碟。

Java

drive/snippets/drive_v3/src/main/java/RecoverDrive.java
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.Drive;
import com.google.api.services.drive.model.DriveList;
import com.google.api.services.drive.model.Permission;
import com.google.auth.http.HttpCredentialsAdapter;
import com.google.auth.oauth2.GoogleCredentials;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/* class to demonstrate use-case of Drive's shared drive without an organizer. */
public class RecoverDrive {

  /**
   * Find all shared drives without an organizer and add one.
   *
   * @param realUser User's email id.
   * @return All shared drives without an organizer.
   * @throws IOException if shared drive not found.
   */
  public static List<Drive> recoverDrives(String realUser)
      throws IOException {
        /*Load pre-authorized user credentials from the environment.
        TODO(developer) - See https://developers.google.com/identity for
        guides on implementing OAuth2 for your application.*/
    GoogleCredentials credentials =
        GoogleCredentials.getApplicationDefault().createScoped(Arrays.asList(DriveScopes.DRIVE));
    HttpRequestInitializer requestInitializer = new HttpCredentialsAdapter(
        credentials);

    // Build a new authorized API client service.
    com.google.api.services.drive.Drive service =
        new com.google.api.services.drive.Drive.Builder(new NetHttpTransport(),
            GsonFactory.getDefaultInstance(),
            requestInitializer)
            .setApplicationName("Drive samples")
            .build();
    List<Drive> drives = new ArrayList<Drive>();

    // Find all shared drives without an organizer and add one.
    // Note: This example does not capture all cases. Shared drives
    // that have an empty group as the sole organizer, or an
    // organizer outside the organization are not captured. A
    // more exhaustive approach would evaluate each shared drive
    // and the associated permissions and groups to ensure an active
    // organizer is assigned.
    String pageToken = null;
    Permission newOrganizerPermission = new Permission()
        .setType("user")
        .setRole("organizer");

    newOrganizerPermission.setEmailAddress(realUser);


    do {
      DriveList result = service.drives().list()
          .setQ("organizerCount = 0")
          .setFields("nextPageToken, drives(id, name)")
          .setUseDomainAdminAccess(true)
          .setPageToken(pageToken)
          .execute();
      for (Drive drive : result.getDrives()) {
        System.out.printf("Found drive without organizer: %s (%s)\n",
            drive.getName(), drive.getId());
        // Note: For improved efficiency, consider batching
        // permission insert requests
        Permission permissionResult = service.permissions()
            .create(drive.getId(), newOrganizerPermission)
            .setUseDomainAdminAccess(true)
            .setSupportsAllDrives(true)
            .setFields("id")
            .execute();
        System.out.printf("Added organizer permission: %s\n",
            permissionResult.getId());

      }

      drives.addAll(result.getDrives());

      pageToken = result.getNextPageToken();
    } while (pageToken != null);

    return drives;
  }
}

Python

drive/snippets/drive-v3/drive_snippet/recover_drives.py
import google.auth
from googleapiclient.discovery import build
from googleapiclient.errors import HttpError


def recover_drives(real_user):
  """Find all shared drives without an organizer and add one.
  Args:
      real_user:User ID for the new organizer.
  Returns:
      drives object

  Load pre-authorized user credentials from the environment.
  TODO(developer) - See https://developers.google.com/identity
  for guides on implementing OAuth2 for the application.
  """
  creds, _ = google.auth.default()
  try:
    # create drive api client
    service = build("drive", "v3", credentials=creds)

    drives = []

    # pylint: disable=maybe-no-member
    page_token = None
    new_organizer_permission = {
        "type": "user",
        "role": "organizer",
        "emailAddress": "user@example.com",
    }
    new_organizer_permission["emailAddress"] = real_user

    while True:
      response = (
          service.drives()
          .list(
              q="organizerCount = 0",
              fields="nextPageToken, drives(id, name)",
              useDomainAdminAccess=True,
              pageToken=page_token,
          )
          .execute()
      )
      for drive in response.get("drives", []):
        print(
            "Found shared drive without organizer: "
            f"{drive.get('title')}, {drive.get('id')}"
        )
        permission = (
            service.permissions()
            .create(
                fileId=drive.get("id"),
                body=new_organizer_permission,
                useDomainAdminAccess=True,
                supportsAllDrives=True,
                fields="id",
            )
            .execute()
        )
        print(f'Added organizer permission: {permission.get("id")}')

      drives.extend(response.get("drives", []))
      page_token = response.get("nextPageToken", None)
      if page_token is None:
        break

  except HttpError as error:
    print(f"An error occurred: {error}")

  return drives


if __name__ == "__main__":
  recover_drives(real_user="gduser1@workspacesamples.dev")

Node.js

drive/snippets/drive_v3/drive_snippets/recover_drives.js
/**
 * Find all shared drives without an organizer and add one.
 * @param{string} userEmail user ID to assign ownership to
 * */
async function recoverDrives(userEmail) {
  // Get credentials and build service
  // TODO (developer) - Use appropriate auth mechanism for your app

  const {GoogleAuth} = require('google-auth-library');
  const {google} = require('googleapis');

  const auth = new GoogleAuth({
    scopes: 'https://www.googleapis.com/auth/drive',
  });
  const service = google.drive({version: 'v3', auth});
  const drives = [];
  const newOrganizerPermission = {
    type: 'user',
    role: 'organizer',
    emailAddress: userEmail, // Example: 'user@example.com'
  };

  let pageToken = null;
  try {
    const res = await service.drives.list({
      q: 'organizerCount = 0',
      fields: 'nextPageToken, drives(id, name)',
      useDomainAdminAccess: true,
      pageToken: pageToken,
    });
    Array.prototype.push.apply(drives, res.data.items);
    for (const drive of res.data.drives) {
      console.log(
          'Found shared drive without organizer:',
          drive.name,
          drive.id,
      );
      await service.permissions.create({
        resource: newOrganizerPermission,
        fileId: drive.id,
        useDomainAdminAccess: true,
        supportsAllDrives: true,
        fields: 'id',
      });
    }
    pageToken = res.nextPageToken;
  } catch (err) {
    // TODO(developer) - Handle error
    throw err;
  }
  return drives;
}

PHP

drive/snippets/drive_v3/src/DriveRecoverDrives.php
<?php
use Google\Client;
use Google\Service\Drive;
use Ramsey\Uuid\Uuid;
function recoverDrives()
{
   try {
    $client = new Client();
    $client->useApplicationDefaultCredentials();
    $client->addScope(Drive::DRIVE);
    $driveService = new Drive($client);

    $realUser = readline("Enter user email address: ");

    $drives = array();
    // Find all shared drives without an organizer and add one.
    // Note: This example does not capture all cases. Shared drives
    // that have an empty group as the sole organizer, or an
    // organizer outside the organization are not captured. A
    // more exhaustive approach would evaluate each shared drive
    // and the associated permissions and groups to ensure an active
    // organizer is assigned.
    $pageToken = null;
    $newOrganizerPermission = new Drive\Permission(array(
        'type' => 'user',
        'role' => 'organizer',
        'emailAddress' => 'user@example.com'
    ));
    $newOrganizerPermission['emailAddress'] = $realUser;
    do {
        $response = $driveService->drives->listDrives(array(
            'q' => 'organizerCount = 0',
            'fields' => 'nextPageToken, drives(id, name)',
            'useDomainAdminAccess' => true,
            'pageToken' => $pageToken
        ));
        foreach ($response->drives as $drive) {
            printf("Found shared drive without organizer: %s (%s)\n",
                $drive->name, $drive->id);
            $permission = $driveService->permissions->create($drive->id,
                $newOrganizerPermission,
                array(
                    'fields' => 'id',
                    'useDomainAdminAccess' => true,
                    'supportsAllDrives' => true
                ));
            printf("Added organizer permission: %s\n", $permission->id);
        }
        array_push($drives, $response->drives);
        $pageToken = $response->pageToken;
    } while ($pageToken != null);
    return $drives;
   } catch(Exception $e) {
      echo "Error Message: ".$e;
   }
}

.NET

drive/snippets/drive_v3/DriveV3Snippets/RecoverDrives.cs
using Google.Apis.Auth.OAuth2;
using Google.Apis.Drive.v3;
using Google.Apis.Drive.v3.Data;
using Google.Apis.Services;

namespace DriveV3Snippets
{
    // Class to demonstrate use-case of Drive's shared drive without an organizer.
    public class RecoverDrives
    {
        /// <summary>
        /// Find all shared drives without an organizer and add one.
        /// </summary>
        /// <param name="realUser">User ID for the new organizer.</param>
        /// <returns>all shared drives without an organizer.</returns>
        public static IList<Drive> DriveRecoverDrives(string realUser)
        {
            try
            {
                /* Load pre-authorized user credentials from the environment.
                 TODO(developer) - See https://developers.google.com/identity for
                 guides on implementing OAuth2 for your application. */
                GoogleCredential credential = GoogleCredential.GetApplicationDefault()
                    .CreateScoped(DriveService.Scope.Drive);

                // Create Drive API service.
                var service = new DriveService(new BaseClientService.Initializer
                {
                    HttpClientInitializer = credential,
                    ApplicationName = "Drive API Snippets"
                });

                var drives = new List<Drive>();
                // Find all shared drives without an organizer and add one.
                // Note: This example does not capture all cases. Shared drives
                // that have an empty group as the sole organizer, or an
                // organizer outside the organization are not captured. A
                // more exhaustive approach would evaluate each shared drive
                // and the associated permissions and groups to ensure an active
                // organizer is assigned.
                string pageToken = null;
                var newOrganizerPermission = new Permission()
                {
                    Type = "user",
                    Role = "organizer",
                    EmailAddress = realUser
                };

                do
                {
                    var request = service.Drives.List();
                    request.UseDomainAdminAccess = true;
                    request.Q = "organizerCount = 0";
                    request.Fields = "nextPageToken, drives(id, name)";
                    request.PageToken = pageToken;
                    var result = request.Execute();
                    foreach (var drive in result.Drives)
                    {
                        Console.WriteLine(("Found abandoned shared drive: {0} ({1})",
                            drive.Name, drive.Id));
                        // Note: For improved efficiency, consider batching
                        // permission insert requests
                        var permissionRequest = service.Permissions.Create(
                            newOrganizerPermission,
                            drive.Id
                        );
                        permissionRequest.UseDomainAdminAccess = true;
                        permissionRequest.SupportsAllDrives = true;
                        permissionRequest.Fields = "id";
                        var permissionResult = permissionRequest.Execute();
                        Console.WriteLine("Added organizer permission: {0}", permissionResult.Id);
                    }

                    pageToken = result.NextPageToken;
                } while (pageToken != null);

                return drives;
            }
            catch (Exception e)
            {
                // TODO(developer) - handle error appropriately
                if (e is AggregateException)
                {
                    Console.WriteLine("Credential Not found");
                }
                else
                {
                    throw;
                }
            }
            return null;
        }
    }
}

禁止使用者下載、列印或複製你的檔案

您可以限制使用者在共用雲端硬碟中下載、列印及複製檔案的方式。

如要判斷使用者是否可以變更主辦人對共用雲端硬碟套用的下載限制,請檢查 capabilities.canChangeDownloadRestriction 布林值欄位。如果「capabilities.canChangeDownloadRestriction」設為「true」,則可對共用雲端硬碟套用下載限制。詳情請參閱「瞭解檔案功能」。

drives 資源包含一組布林值 restrictions 欄位,用於指出是否可對共用雲端硬碟執行動作。限制適用於共用雲端硬碟或共用雲端硬碟內的項目。 您可以使用 drives.update 方法設定限制。

如要對共用雲端硬碟套用下載限制,共用雲端硬碟管理員可以使用 DownloadRestriction 物件,設定 drives 資源的 restrictions.downloadRestriction 欄位。將 restrictedForReaders 布林值欄位設為 true,表示讀者無法下載及複製檔案。將 restrictedForWriters 布林值欄位設為 true,即表示寫手無法下載及複製檔案。請注意,如果 restrictedForWriters 欄位為 true,讀者也無法下載及複製內容。同樣地,將 restrictedForWriters 設為 true,並將 restrictedForReaders 設為 false,等同於將 restrictedForWritersrestrictedForReaders 都設為 true

回溯相容性

隨著 DownloadRestriction 物件的推出,restrictions.copyRequiresWriterPermission 布林值欄位的功能也已更新。

現在,將 restrictions.copyRequiresWriterPermission 設為 true 會將 DownloadRestriction 物件的 restrictedForReaders 布林值欄位更新為 true,表示讀者無法下載及複製內容。

copyRequiresWriterPermission 欄位設為 false,即可將 restrictedForWritersrestrictedForReaders 欄位更新為 false。也就是說,所有使用者的下載或複製限制設定都會移除。

控管下載、列印和複製功能的欄位

下表列出會影響下載、列印和複製功能的 drives 資源欄位:

欄位 說明 版本
capabilities.canCopy 目前使用者是否可以複製共用雲端硬碟中的檔案。 v2 和 v3
capabilities.canDownload 目前使用者是否可以下載共用雲端硬碟中的檔案。 v2 和 v3
capabilities.canChangeCopyRequiresWriterPermission 目前使用者是否可以變更共用雲端硬碟的 copyRequiresWriterPermission 限制。 v2 和 v3
capabilities.canResetDriveRestrictions 目前使用者是否可以將共用雲端硬碟限制重設為預設值。 v2 和 v3
capabilities.canChangeDownloadRestriction 目前使用者是否可以變更共用雲端硬碟的下載限制。 僅限 v3
restrictions.copyRequiresWriterPermission 是否禁止讀者和加註者複製、列印或下載共用雲端硬碟中的檔案。true,系統會將共用雲端硬碟中所有檔案的同名欄位設為 true v2 和 v3
restrictions.downloadRestriction 共用雲端硬碟管理員套用的下載限制。 僅限 v3

資料夾限制

共用雲端硬碟資料夾設有儲存空間上限。詳情請參閱「Google 雲端硬碟的共用雲端硬碟限制」。

項目上限

每個使用者的共用雲端硬碟最多可容納 500,000 個項目,包括檔案、資料夾和捷徑。

達到上限後,共用雲端硬碟就無法再接受項目。如要繼續接收檔案,使用者必須從共用雲端硬碟中永久刪除項目。請注意,垃圾桶中的項目會計入上限,但永久刪除的項目則不會。詳情請參閱「將檔案和資料夾移至垃圾桶或刪除」。

資料夾深度限制

共用雲端硬碟中的單一資料夾最多只能建立 100 層巢狀資料夾。 也就是說,子資料夾不能儲存在超過 99 層的資料夾中。這項限制僅適用於子資料夾。

如果嘗試新增超過 100 層的資料夾,系統會傳回 teamDriveHierarchyTooDeep HTTP 狀態碼回應。