Google Drive SDK

Revisions: patch

Requires authorization

Updates a revision. This method supports patch semantics. Try it now or see an example.

Request

HTTP request

PATCH https://www.googleapis.com/drive/v2/files/fileId/revisions/revisionId

Parameters

Parameter name Value Description
Path parameters
fileId string The ID for the file.
revisionId string The ID for the revision.

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.appdata

Request body

In the request body, supply a Revisions resource.

Response

If successful, this method returns a Revisions 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.Revision;

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

public class MyClass {

  // ...

  /**
   * Pin a revision.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to update revision for.
   * @param revisionId ID of the revision to pin.
   * @return The patched revision if successful, {@code null} otherwise.
   */
  private static Revision pinRevision(Drive service, String fileId,
      String revisionId) {
    Revision patchedRevision = new Revision();
    patchedRevision.setPinned(true);
    try {
      return service.revisions().patch(
          fileId, revisionId, patchedRevision).execute();
    } 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.Net;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Pin a revision.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to update revision for.</param>
  /// <param name="revisionId">ID of the revision to pin.</param>
  /// <returns>The patched revision, null is returned if an API error occurred</returns>
  public static Revision PinRevision(DriveService service, String fileId,
      String revisionId) {
    Revision patchedRevision = new Revision();
    patchedRevision.Pinned = true;
    try {
      return service.Revisions.Patch(patchedRevision, fileId, revisionId).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library

/**
 * Pin a revision.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to update revision for.
 * @param String $revisionId ID of the revision to pin.
 * @return Google_Revision The patched revision. NULL is returned if an API error occurred.
 */
function pinRevision($service, $fileId, $revisionId) {
  $patchedRevision = new Google_Revision();
  $patchedRevision->setPinned(true);
  try {
    return $service->revisions->patch($fileId, $revisionId, $patchedRevision);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library

from apiclient import errors
# ...

def pin_revision(service, file_id, revision_id):
  """Pin a revision.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to update revision for.
    revision_id: ID of the revision to pin.

  Returns:
    The patched revision if successful, None otherwise.
  """
  patched_revision = {'pinned': True}
  try:
    return service.revisions().patch(
        fileId=file_id, revisionId=revision_id,
        body=patched_revision).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

Ruby

Uses the Ruby client library

##
# Pin a revision
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to update revision for
# @param [String] revision_id
#   ID of the revision to patch
# @return [Google::APIClient::Schema::Drive::V2::Revision]
#   The patched revision if successful, nil otherwise
def pin_revision(client, file_id, revision_id)

  drive = client.discovered_api('drive', 'v2')
  patched_revision = drive.revisions.patch.request_schema.new({
    'pinned' => true
  })
  result = client.execute(
    :api_method => drive.revisions.patch,
    :body_object => patched_revision,
    :parameters => {
      'fileId' => file_id,
      'revisionId' => revision_id
    })
  if result.status == 200
    return result.data
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Pin a revision.
 *
 * @param {String} fileId ID of the file to update revision for.
 * @param {String} revisionId ID of the revision to pin.
 */
function pinRevision(fileId, revisionId) {
  var body = {'pinned': true};
  var request = gapi.client.drive.revisions.patch({
    'fileId': fileId,
    'revisionId': revisionId,
    'resource': body
  });
  request.execute(function(resp) { });
}

Go

Uses the Go client library

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

// PatchRevision patches a revision to be pinned
func PatchRevision(d *drive.Service, fileId string, revisionId string) error {
  r := &drive.Revision{Pinned: true}
  _, err := d.Revisions.Patch(fileId, revisionId, r).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)pinRevisionWithService:(GTLServiceDrive *)service
                        fileId:(NSString *)fileId
                    revisionId:(NSString *)revisionId
               completionBlock:(void (^)(GTLDriveRevision *, NSError *))completionBlock {
  GTLDriveRevision *patchedRevision = [GTLDriveRevision object];
  patchedRevision.pinned = @YES;

  GTLQueryDrive *query =
    [GTLQueryDrive queryForRevisionsPatchWithObject:patchedRevision
                                             fileId:fileId
                                         revisionId:revisionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveRevision *revision, NSError *error) {
          if (error == nil) {
            completionBlock(revision, 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.

Authentication required

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

Signing you in...

Google Developers needs your permission to do that.