Google Drive SDK

Permissions: get

Requires authorization

Gets a permission by ID. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
fileId string The ID for the file.
permissionId string The ID for the permission.

Authorization

This request requires authorization with at least one of the following scopes (read more about authentication and authorization).

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

Request body

Do not supply a request body with this method.

Response

If successful, this method returns a Permissions resource in the 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 com.google.api.services.drive.model.Permission;

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

public class MyClass {

  // ...

  /**
   * Print information about the specified permission.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to print permission for.
   * @param permissionId ID of the permission to print.
   */
  private static void printPermission(Drive service, String fileId,
      String permissionId) {
    try {
      Permission permission = service.permissions().get(
          fileId, permissionId).execute();

      System.out.println("Name: " + permission.getName());
      System.out.println("Role: " + permission.getRole());
      for (String additionalRole : permission.getAdditionalRoles()) {
        System.out.println("Additional role: " + additionalRole);
      }
    } catch (IOException e) {
      System.out.println("An error occured: " + 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>Print information about the specified permission.</summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to print permission for.</param>
  /// <param name="permissionId">ID of the permission to print.</param>
  public static void PrintPermission(DriveService service, String fileId,
      String permissionId) {
    try {
      Permission permission = service.Permissions.Get(
          fileId, permissionId).Fetch();

      Console.WriteLine("Name: " + permission.Name);
      Console.WriteLine("Role: " + permission.Role);
      foreach (String additionalRole in permission.AdditionalRoles) {
        Console.WriteLine("Additional role: " + additionalRole);
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...

}

PHP

Uses the PHP client library

/**
 * Print information about the specified permission.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to print permission for.
 * @param String $permissionId ID of the permission to print.
 */
function printPermission($service, $fileId, $permissionId) {
  try {
    $permission = $service->permissions->get($fileId, $permissionId);

    print "Name: " . $permission->getName();
    print "Role: " . $permission->getRole();
    $additionalRoles = $permission->getAdditionalRoles();
    if(!empty($additionalRoles)) {
      foreach($additionalRoles as $additionalRole) {
        print "Additional role: " . $additionalRole;
      }
    }
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library

from apiclient import errors
# ...

def print_permission(service, file_id, permission_id):
  """Print information about the specified permission.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to print permission for.
    permission_id: ID of the permission to print.
  """
  try:
    permission = service.permissions().get(
        fileId=file_id, permissionId=permission_id).execute()

    print 'Name: %s' % permission['name']
    print 'Role: %s' % permission['role']
    for additional_role in permission.get('additionalRole', []):
      print 'Additional role: %s' % additional_role
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

Uses the Ruby client library

##
# Print information about the specified permission.
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to print permission for
# @param [String] permission_id
#   ID of the permission to print
# @return nil
def print_permission(client, file_id, permission_id)

  drive = client.discovered_api('drive', 'v2')
  result = client.execute(
    :api_method => drive.permissions.get,
    :parameters => {
      'fileId' => file_id,
      'permissionId' => permission_id
    })
  if result.status == 200
    permission = result.data
    puts "Name: #{permission.name}"
    puts "Role: #{permission.role}"
    permission.additional_role.each do |additional_role|
      puts "Additional role: #{additional_role}"
    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Print information about the specified permission.
 *
 * @param {String} fileId ID of the file to print permission for.
 * @param {String} permissionId ID of the permission to print.
 */
function printPermission(fileId, permissionId) {
  var request = gapi.client.drive.permissions.get({
    'fileId': fileId,
    'permissionId': permissionId
  });
  request.execute(function(resp) {
    console.log('Name: ' + resp.name);
    console.log('Role: ' + resp.role);
    for (role in resp.additionalRoles) {
      console.log('Additional role: ' + resp.additionalRoles[role]);
    }
  });
}

Go

Uses the Go client library

import (
  "code.google.com/p/google-api-go-client/drive/v2"
  "fmt"
)


// PrintPermission displays the given permission on the given file
func PrintPermission(d *drive.Service, fileId string, permissionId string) error {
  p, err := d.Permissions.Get(fileId, permissionId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  fmt.Printf("Role: %v\n", p.Role)
  return nil
}

Objective-C

Uses the Objective-C client library

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

+ (void)printPermissionWithService:(GTLServiceDrive *)service
                            fileId:(NSString *)fileId
                      permissionId:(NSString *)permissionId {
  GTLQueryDrive *query =
    [GTLQueryDrive queryForPermissionsGetWithFileId:fileId
                                       permissionId:permissionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDrivePermission *permission, NSError *error) {
          if (error == nil) {
            NSLog(@"Name: %@", permission.name);
            NSLog(@"Role: %@", permission.role);
            for (NSString *additionalRole in permission.additionalRoles) {
              NSLog(@"Additional role: %@", additionalRole);
            }
          } else {
            NSLog(@"An error occurred: %@", error);
          }
        }];
}

// ...

Try it!

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

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.