Google Drive SDK

Revisions: list

Requires authorization

Lists a file's revisions. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
fileId string The ID of the file.

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

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#revisionList",
  "etag": etag,
  "selfLink": string,
  "items": [
    revisions Resource
  ]
}
Property name Value Description Notes
kind string This is always drive#revisionList.
etag etag The ETag of the list.
items[] list The actual list of revisions.

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 com.google.api.services.drive.model.RevisionList;

import java.io.IOException;
import java.util.List;

// ...

public class MyClass {

  // ...

  /**
   * Retrieve a list of revisions.
   *
   * @param service Drive API service instance.
   * @param fileId ID of the file to retrieve revisions for.
   * @return List of revisions.
   */
  private static List<Revision> retrieveRevisions(Drive service,
      String fileId) {
    try {
      RevisionList revisions = service.revisions().list(fileId).execute();
      return revisions.getItems();
    } 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.Collections.Generic;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Retrieve a list of revisions.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="fileId">ID of the file to retrieve revisions for.</param>
  /// <returns>List of revisions.</returns>
  public static IList<Revision> RetrieveRevisions(DriveService service, String fileId) {
    try {
      RevisionList revisions = service.Revisions.List(fileId).Fetch();
      return revisions.Items;
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
    return null;
  }

  // ...

}

PHP

Uses the PHP client library

/**
 * Retrieve a list of revisions.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $fileId ID of the file to retrieve revisions for.
 * @return Array List of Google_Revision resources.
 */
function retrieveRevisions($service, $fileId) {
  try {
    $revisions = $service->revisions->listRevisions($fileId);
    return $revisions->getItems();
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
  return NULL;
}

Python

Uses the Python client library

from apiclient import errors
# ...

def retrieve_revisions(service, file_id):
  """Retrieve a list of revisions.

  Args:
    service: Drive API service instance.
    file_id: ID of the file to retrieve revisions for.
  Returns:
    List of revisions.
  """
  try:
    revisions = service.revisions().list(fileId=file_id).execute()
    return revisions.get('items', [])
  except errors.HttpError, error:
    print 'An error occurred: %s' % error
  return None

Ruby

Uses the Ruby client library

##
# Retrieve a list of revisions
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] file_id
#   ID of the file to retrieve revisions for
# @return [Array]
#   List of revisions
def retrieve_revisions(client, file_id)

  drive = client.discovered_api('drive', 'v2')
  api_result = client.execute(
    :api_method => drive.revisions.list,
    :parameters => { 'fileId' => file_id })
  if api_result.status == 200
    revisions = api_result.data
    return revisions.items
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Retrieve a list of revisions.
 *
 * @param {String} fileId ID of the file to retrieve revisions for.
 * @param {Function} callback Function to call when the request is complete.
 */
function retrieveRevisions(fileId, callback) {
  var request = gapi.client.drive.revisions.list({
    'fileId': fileId
  });
  request.execute(callback);
}

Go

Uses the Go client library

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

// AllRevisions fetches all revisions for a given file
func AllRevisions(d *drive.Service, fileId string) ([]*drive.Revision, error) {
  r, err := d.Revisions.List(fileId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return nil, err
  }
  return r.Items, nil
}

Objective-C

Uses the Objective-C client library

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

+ (void)retrieveRevisionsWithService:(GTLServiceDrive *)service
                              fileId:(NSString *)fileId
                     completionBlock:(void (^)(NSArray *, NSError *))completionBlock {
  GTLQueryDrive *query =
    [GTLQueryDrive queryForRevisionsListWithFileId:fileId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket,
                            GTLDriveRevisionList *revisions, NSError *error) {
          if (error == nil) {
            completionBlock(revisions.items, 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.