Google Drive SDK

Revisions: update

Requires authorization

Updates a revision. Try it now or see an example.

Request

HTTP request

PUT 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 with the following properties:

Property name Value Description Notes
Optional Properties
pinned boolean Whether this revision is pinned to prevent automatic purging. This will only be populated and can only be modified on files with content stored in Drive which are not Google Docs. Revisions can also be pinned when they are created through the drive.files.insert/update/copy by using the pinned query parameter. writable
publishAuto boolean Whether subsequent revisions will be automatically republished. This is only populated and can only be modified for Google Docs. writable
published boolean Whether this revision is published. This is only populated and can only be modified for Google Docs. writable
publishedOutsideDomain boolean Whether this revision is published outside the domain. This is only populated and can only be modified for Google Docs. writable

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 update.
   * @return The updated revision if successful, {@code null} otherwise.
   */
  private static Revision updateRevision(Drive service, String fileId,
      String revisionId) {
    try {
      // First retrieve the revision from the API.
      Revision revision = service.revisions().get(
          fileId, revisionId).execute();
      revision.setPinned(true);
      return service.revisions().update(
          fileId, revisionId, revision).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 update.</param>
  /// <returns>The updated revision, null is returned if an API error occurred</returns>
  public static Revision UpdateRevision(DriveService service, String fileId,
      String revisionId) {
    try {
      // First retrieve the revision from the API.
      Revision revision = service.Revisions.Get(fileId, revisionId).Fetch();
      revision.Pinned = true;
      return service.Revisions.Update(revision, 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 update.
 * @return Google_Revision The updated revision. NULL is returned if an API error occurred.
 */
function updateRevision($service, $fileId, $revisionId) {
  try {
    // First retrieve the revision from the API.
    $revision = $service->revisions->get($fileId, $revisionId);
    $revision->setPinned(true);
    return $service->revisions->update($fileId, $revisionId, $revision);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library

from apiclient import errors
# ...

def update_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 update.

  Returns:
    The updated revision if successful, None otherwise.
  """
  try:
    # First retrieve the revision from the API.
    revision = service.revisions().get(
        fileId=file_id, revisionId=revision_id).execute()
    revision['pinned'] = True
    return service.revisions().update(
        fileId=file_id, revisionId=revision_id, body=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 update
# @return [Google::APIClient::Schema::Drive::V2::Revision]
#   The updated revision if successful, nil otherwise
def update_revision(client, file_id, revision_id)

  drive = client.discovered_api('drive', 'v2')# First retrieve the revision from the API.
  result = client.execute(
    :api_method => drive.revisions.get,
    :parameters => {
      'fileId' => file_id,
      'revisionId' => revision_id
    })
  if result.status == 200
    revision = result.data
    revision.pinned = true
    result = client.execute(
      :api_method => drive.revisions.update,
      :body_object => updated_revision,
      :parameters => {
        'fileId' => file_id,
        'revisionId' => revision_id
      })
    if result.status == 200
      return result.data
    end
  end
  puts "An error occurred: #{result.data['error']['message']}"
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 update.
 */
function updateRevision(fileId, revisionId) {
  // First retrieve the permission from the API.
  var request = gapi.client.drive.revisions.get({
    'fileId': fileId,
    'revisionId': revisionId
  });
  request.execute(function(resp) {
    resp.pinned = true;
    var updateRequest = gapi.client.drive.revisions.update({
      'fileId': fileId,
      'revisionId': revisionId,
      'resource': resp
    });
    updateRequest.execute(function(resp) { });
  });
}

Go

Uses the Go client library

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

// UpdateRevision fetches and updates a revision to be pinned
func UpdateRevision(d *drive.Service, fileId string, revisionId string,
    role string) error {
  r, err := d.Revisions.Get(fileId, revisionId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  r.Pinned = true
  _, err = d.Revisions.Update(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)updateRevisionWithService:(GTLServiceDrive *)service
                           fileId:(NSString *)fileId
                       revisionId:(NSString *)revisionId
                  completionBlock:(void (^)(GTLDriveRevision*, NSError *))completionBlock {
  GTLQueryDrive *getQuery =
    [GTLQueryDrive queryForRevisionsGetWithFileId:fileId
                                       revisionId:revisionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:getQuery
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveRevision *revision, NSError *error) {
          if (error == nil) {
            revision.pinned = @YES;
            GTLQueryDrive *updateQuery =
              [GTLQueryDrive queryForRevisionsUpdateWithObject:revision
                                                      fileId:fileId
                                                  revisionId:revisionId];
            // executeQuery returns a ticket object that can be used to track
            // progress of the request.
            [service executeQuery:updateQuery
                completionHandler:^(GTLServiceTicket *ticket,
                                    GTLDriveRevision *revision, NSError *error) {
                  if (error == nil) {
                    completionBlock(revision, nil);
                  } else {
                    NSLog(@"An error occurred: %@", error);
                    completionBlock(nil, error);
                  }
                }];
          } 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.