Permissions: getIdForEmail

Requires authorization

Returns the permission ID for an email address. Try it now or see an example.

Request

HTTP request

GET https://www.googleapis.com/drive/v2/permissionIds/email

Parameters

Parameter name Value Description
Path parameters
email string The email address for which to return a permission ID

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
https://www.googleapis.com/auth/drive.appdata
https://www.googleapis.com/auth/drive.apps.readonly
https://www.googleapis.com/auth/drive.metadata
https://www.googleapis.com/auth/drive.photos.readonly

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#permissionId",
  "id": string
}
Property name Value Description Notes
kind string This is always drive#permissionId.
id string The permission ID.

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.PermissionId;

import java.io.IOException;

public class MyClass {

  /**
   * Print the Permission ID for an email address.
   *
   * @param service Drive API service instance.
   * @param email Email address to retrieve ID for.
   */
  private static void printPermissionIdForEmail(Drive service, String email) {
    try {
      PermissionId permissionId =
         service.permissions().getIdForEmail(email).execute();

      System.out.println("ID: " + permissionId.getId());
    } 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 the Permission ID for an email address.</summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="email">Email address to retrieve ID for.</param>
  public static void PrintPermissionIdForEmail(DriveService service, String email) {
    try {
      PermissionId permissionId =
          service.Permissions.GetIdForEmail(email).Execute();

      Console.WriteLine("ID: " + permission.Id);
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }
}

PHP

Uses the PHP client library.

/**
 * Print the Permission ID for an email address.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $email Email address to retrieve ID for.
 */
function printPermissionIdForEmail($service, $email) {
  try {
    $permissionId = $service->permissions->getIdForEmail($email);

    print "ID: " . $permissionId->getId();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library.

from apiclient import errors

def print_permission_id_for_email(service, email):
  """Prints the Permission ID for an email address.

  Args:
    service: Drive API service instance.
    email: Email address to retrieve ID for.
  """
  try:
    id_resp = service.permissions().getIdForEmail(email=email).execute()
    print id_resp['id']
  except errors.HttpError, error:
    print 'An error occured: %s' % error

Go

Uses the Go client library.

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

// PrintPermissionIdForEmail Prints the Permission ID for an email address.
func PrintPermission(d *drive.Service, email string) error {
  p, err := d.Permissions.GetIdForEmail(email).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  fmt.Printf("ID: %v\n", p.Id)
  return nil
}

JavaScript

Uses the JavaScript client library.

/**
 * Print the Permission ID for an email address. 
 *
 * @param {String} email Email address to retrieve ID for.
 */
function printPermissionIdForEmail(email) {
  var request = gapi.client.drive.permissions.getIdForEmail({
    'email': email,
  });
  request.execute(function(resp) {
    console.log('ID: ' + resp.id);
  });
}

Objective-C

Uses the Objective-C client library.

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

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

Try it!

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

Send feedback about...

Drive REST API v2
Drive REST API v2