Google Drive SDK

Revisions: delete

Requires authorization

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

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
fileId string The ID of the file.
revisionId string The ID of 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

Do not supply a request body with this method.

Response

If successful, this method returns an empty 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 java.io.IOException;
// ...

public class MyClass {

  // ...

  /**
   * Remove a revision.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to remove the revision for.
   * @param revisionId ID of the revision to remove.
   */
  private static void removeRevision(Drive service, String fileId,
      String revisionId) {
    try {
      service.revisions().delete(fileId, revisionId).execute();
    } 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>
  /// Remove a revision.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to remove the revision for.</param>
  /// <param name="revisionId">ID of the revision to remove.</param>
  public static void RemoveRevision(DriveService service, String fileId,
      String revisionId) {
    try {
      service.Revisions.Delete(fileId, revisionId).Fetch();
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...

}

PHP

Uses the PHP client library

/**
 * Remove a revision.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to remove the revision for.
 * @param String $revisionId ID of the revision to remove.
 */
function removeRevision($service, $fileId, $revisionId) {
  try {
    $service->revisions->delete($fileId, $revisionId);
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library

from apiclient import errors
# ...

def remove_revision(service, file_id, revision_id):
  """Remove a revision.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to remove the revision for.
    revision_id: ID of the revision to remove.
  """
  try:
    service.revisions().delete(
        fileId=file_id, revisionId=revision_id).execute()
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

Uses the Ruby client library

##
# Remove a revision
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to remove the revision for
# @param [String] revision_id
#   ID of the revision to remove
# @return nil
def remove_revision(client, file_id, revision_id)

  drive = client.discovered_api('drive', 'v2')
  result = client.execute(
    :api_method => drive.revisions.delete,
    :parameters => {
      'fileId' => file_id,
      'revisionId' => revision_id })
  if result.status != 200
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Remove a revision.
 *
 * @param {String} fileId ID of the file to remove the revision for.
 * @param {String} revisionId ID of the revision to remove.
 */
function removeRevision(fileId, revisionId) {
  var request = gapi.client.drive.revisions.delete({
    'fileId': fileId,
    'revisionId': revisionId
  });
  request.execute(function(resp) { });
}

Go

Uses the Go client library

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


// RemoveRevision removes the given revision from the given file
func RemoveRevision(d *drive.Service, fileId string, revisionId string) error {
  err := d.Revisions.Delete(fileId, revisionId).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)removeRevisionWithService:(GTLServiceDrive *)service
                           fileId:(NSString *)fileId
                       revisionId:(NSString *)revisionId {
  GTLQueryDrive *query =
    [GTLQueryDrive queryForRevisionsDeleteWithFileId:fileId
                                          revisionId:revisionId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, id object, NSError *error) {
          if (error != nil) {
            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.