Permissions: delete

Deletes a permission from a file or shared drive. Try it now or see an example.

Warning: Concurrent permissions operations on the same file are not supported; only the last update is applied.

Request

HTTP request

DELETE https://www.googleapis.com/drive/v2/files/fileId/permissions/permissionId

Parameters

Parameter name Value Description
Path parameters
fileId string The ID for the file or shared drive.
permissionId string The ID for the permission.
Optional query parameters
supportsAllDrives boolean Deprecated - Whether the requesting application supports both My Drives and shared drives. This parameter will only be effective until June 1, 2020. Afterwards all applications are assumed to support shared drives. (Default: false)
supportsTeamDrives boolean Deprecated use supportsAllDrives instead. (Default: false)
useDomainAdminAccess boolean Issue the request as a domain administrator; if set to true, then the requester will be granted access if the file ID parameter refers to a shared drive and the requester is an administrator of the domain to which the shared drive belongs. (Default: false)

Authorization

This request requires authorization with at least one of the following scopes:

Scope
https://www.googleapis.com/auth/drive
https://www.googleapis.com/auth/drive.file

Some scopes are restricted and require a security assessment for your app to use them. For more information, see the authentication and authorization page.

Request body

Do not supply a request body with this method.

Response

If successful, this method returns an empty response body.

Examples

Note: The code examples available for this method do not represent all supported programming languages (see the client libraries page for a list of supported languages).

Java

Uses the Java client library.

import com.google.api.services.drive.Drive;

import java.io.IOException;
// ...

public class MyClass {

  // ...

  /**
   * Remove a permission.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to remove the permission for.
   * @param permissionId ID of the permission to remove.
   */
  private static void removePermission(Drive service, String fileId,
      String permissionId) {
    try {
      service.permissions().delete(fileId, permissionId).execute();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }
  }

  // ...

}

.NET

Uses the .NET client library.

using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

using System.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Remove a permission.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to remove the permission for.</param>
  /// <param name="permissionId">ID of the permission to remove.</param>
  public static void RemovePermission(DriveService service, String fileId,
      String permissionId) {
    try {
      service.Permissions.Delete(fileId, permissionId).Execute();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Remove a permission.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to remove the permission for.
 * @param String $permissionId ID of the permission to remove.
 */
function removePermission($service, $fileId, $permissionId) {
  try {
    $service->permissions->delete($fileId, $permissionId);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library.

from apiclient import errors
# ...

def remove_permission(service, file_id, permission_id):
  """Remove a permission.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to remove the permission for.
    permission_id: ID of the permission to remove.
  """
  try:
    service.permissions().delete(
        fileId=file_id, permissionId=permission_id).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

JavaScript

Uses the JavaScript client library.

/**
 * Remove a permission.
 *
 * @param {String} fileId ID of the file to remove the permission for.
 * @param {String} permissionId ID of the permission to remove.
 */
function removePermission(fileId, permissionId) {
  var request = gapi.client.drive.permissions.delete({
    'fileId': fileId,
    'permissionId': permissionId
  });
  request.execute(function(resp) { });
}

Go

Uses the Go client library.

import (
  "google.golang.org/drive/v2"
  "fmt"
)

// RemovePermission removes the given permission from the given file
func RemovePermission(d *drive.Service, fileId string, permissionId string) error {
  err := d.Permissions.Delete(fileId, permissionId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  return nil
}

Objective-C

Uses the Objective-C client library.

#import "GTLDrive.h"
// ...

+ (void)removePermissionWithService:(GTLServiceDrive *)service
                             fileId:(NSString *)fileId
                       permissionId:(NSString *)permissionId {
  GTLQueryDrive *query =
    [GTLQueryDrive queryForPermissionsDeleteWithFileId:fileId
                                          permissionId:permissionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, id object,
                            NSError *error) {
          if (error != nil) {
            NSLog(@"An error occurred: %@", error);
          }
        }];
}

// ...

Try it!

Use the APIs Explorer below to call this method on live data and see the response.