Permissions: list

Stay organized with collections Save and categorize content based on your preferences.

Lists a file's or shared drive's permissions. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
fileId string The ID for the file or shared drive.
Optional query parameters
includePermissionsForView string Specifies which additional view's permissions to include in the response. Only 'published' is supported.
maxResults integer The maximum number of permissions to return per page. When not set for files in a shared drive, at most 100 results will be returned. When not set for files that are not in a shared drive, the entire list will be returned. Acceptable values are 1 to 100, inclusive.
pageToken string The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response.
supportsAllDrives boolean Whether the requesting application supports both My Drives and 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
https://www.googleapis.com/auth/drive.readonly
https://www.googleapis.com/auth/drive.metadata.readonly
https://www.googleapis.com/auth/drive.metadata
https://www.googleapis.com/auth/drive.photos.readonly

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 a response body with the following structure:

{
  "kind": "drive#permissionList",
  "etag": etag,
  "selfLink": string,
  "nextPageToken": string,
  "items": [
    permissions Resource
  ]
}
Property name Value Description Notes
kind string This is always drive#permissionList.
etag etag The ETag of the list.
items[] list The list of permissions.
nextPageToken string The page token for the next page of permissions. This field will be absent if the end of the permissions list has been reached. If the token is rejected for any reason, it should be discarded, and pagination should be restarted from the first page of results.

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 com.google.api.services.drive.model.Permission;
import com.google.api.services.drive.model.PermissionList;

import java.io.IOException;
import java.util.List;

// ...

public class MyClass {

  // ...

  /**
   * Retrieve a list of permissions.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to retrieve permissions for.
   * @return List of permissions.
   */
  private static List<Permission> retrievePermissions(Drive service,
      String fileId) {
    try {
      PermissionList permissions = service.permissions().list(fileId).execute();
      return permissions.getItems();
    } catch (IOException e) {
      System.out.println("An error occurred: " + e);
    }

    return null;
  }

  // ...

}

.NET

Uses the .NET client library.

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

using System.Collections.Generic;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Retrieve a list of permissions.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to retrieve permissions for.</param>
  /// <returns>List of permissions.</returns>
  public static IList<Permission> RetrievePermissions(DriveService service, String fileId) {
    try {
      PermissionList permissions = service.Permissions.List(fileId).Execute();
      return permissions.Items;
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Retrieve a list of permissions.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to retrieve permissions for.
 * @return Array List of permissions.
 */
function retrievePermissions($service, $fileId) {
  try {
    $permissions = $service->permissions->listPermissions($fileId);
    return $permissions->getItems();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library.

from apiclient import errors
# ...

def retrieve_permissions(service, file_id):
  """Retrieve a list of permissions.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to retrieve permissions for.
  Returns:
    List of permissions.
  """
  try:
    permissions = service.permissions().list(fileId=file_id).execute()
    return permissions.get('items', [])
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

JavaScript

Uses the JavaScript client library.

/**
 * Retrieve a list of permissions.
 *
 * @param {String} fileId ID of the file to retrieve permissions for.
 * @param {Function} callback Function to call when the request is complete.
 */
function retrievePermissions(fileId, callback) {
  var request = gapi.client.drive.permissions.list({
    'fileId': fileId
  });
  request.execute(function(resp) {
    callback(resp.items);
  });
}

Go

Uses the Go client library.

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


// AllPermissions fetches all permissions for a given file
func AllPermissions(d *drive.Service, fileId string) ([]*drive.Permission, error) {
  r, err := d.Permissions.List(fileId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return nil, err
  }
  return r.Items, nil
}

Objective-C

Uses the Objective-C client library.

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

+ (void)retrievePermissionsWithService:(GTLServiceDrive *)service
                                fileId:(NSString *)fileId
                       completionBlock:(void (^)(NSArray *, NSError *))completionBlock {
  GTLQueryDrive *query =
    [GTLQueryDrive queryForPermissionsListWithFileId:fileId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDrivePermissionList *permissions, NSError *error) {
          if (error == nil) {
            completionBlock(permissions.items, nil);
          } else {
            NSLog(@"An error occurred: %@", error);
            completionBlock(nil, error);
          }
        }];
}

// ...

Try it!

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