Properties: get

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

Gets a property by its key. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
fileId string The ID of the file.
propertyKey string The key of the property.
Optional query parameters
visibility string The visibility of the property.

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.appdata
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 Properties 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.Drive.Properties.Get;
import com.google.api.services.drive.model.Property;

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

public class MyClass {

  // ...

  /**
   * Print information about the specified custom property.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to print property for.
   * @param key ID of the property to print.
   * @param visibility The type of property ('PUBLIC' or 'PRIVATE').
   */
  private static void printProperty(Drive service, String fileId, String key, String visibility) {
    try {
      Get request = service.properties().get(fileId, key);
      request.setVisibility(visibility);
      Property property = request.execute();

      System.out.println("Key: " + property.getKey());
      System.out.println("Value: " + property.getValue());
      System.out.println("Visibility: " + property.getVisibility());
    } 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>Print information about the specified custom property.</summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to print property for.</param>
  /// <param name="key">ID of the property to print.</param>
  /// <param name="visibility">type of property ('PUBLIC' or 'PRIVATE').</param>
  public static void PrintProperty(DriveService service, String fileId,
      String key, PropertiesResource.Visibility visibility) {
    try {
      PropertiesResource.GetRequest request =
          service.Properties.Get(fileId, key);
      request.Visibility = visibility;
      Property property = request.Execute();

      Console.WriteLine("Key: " + property.Key);
      Console.WriteLine("Value: " + property.Value);
      Console.WriteLine("Visibility: " + property.Visibility);
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...

}

PHP

Uses the PHP client library.

/**
 * Print information about the specified custom property.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $fileId ID of the file to print property for.
 * @param String $key ID of the property to print.
 * @param String $visibility The type of property ('PUBLIC' or 'PRIVATE').
 */
function printProperty($service, $fileId, $key, $visibility) {
  try {
    $optParams = array('visibility' => $visibility);
    $property = $service->properties->get($fileId, $key, $optParams);

    print "Key: " . $property->getKey();
    print "Value: " . $property->getValue();
    print "Visibility: " . $property->getVisibility();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library.

def print_property(service, file_id, key, visibility):
  """Print information about the specified custom property.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to print property for.
    key: ID of the property to print.
    visibility: type of property ('PUBLIC' or 'PRIVATE').
  """
  try:
    p = service.properties().get(
        fileId=file_id, propertyKey=key, visibility=visibility).execute()

    print 'Key: %s' % p['key']
    print 'Value: %s' % p['value']
    print 'Visibility: %s' % p['visibility']
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

JavaScript

Uses the JavaScript client library.

/**
 * Print information about the specified custom property.
 *
 * @param {String} fileId ID of the file to print property for.
 * @param {String} key ID of the property to print.
 * @param {String} visibility The type of property ('PUBLIC' or 'PRIVATE').
 */
function printProperty(fileId, key, visibility) {
  var request = gapi.client.drive.properties.get({
    'fileId': fileId,
    'propertyKey': key,
    'visibility': visibility
  });
  request.execute(function(resp) {
    console.log('Key: ' + resp.key);
    console.log('Value: ' + resp.value);
    console.log('Visibility: ' + resp.visibility);
  });
}

Try it!

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