Changes: list

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

Lists the changes for a user or shared drive. Try it now or see an example.

For more information, see the Changes and revisions overview.

Request

HTTP request

GET https://www.googleapis.com/drive/v2/changes

Parameters

Parameter name Value Description
Optional query parameters
driveId string The shared drive from which changes are returned. If specified the change IDs will be reflective of the shared drive; use the combined drive ID and change ID as an identifier.
includeCorpusRemovals boolean Whether changes should include the file resource if the file is still accessible by the user at the time of the request, even when a file was removed from the list of changes and there will be no further change entries for this file. (Default: false)
includeDeleted boolean Whether to include changes indicating that items have been removed from the list of changes, for example by deletion or loss of access. (Default: true)
includeItemsFromAllDrives boolean Whether both My Drive and shared drive items should be included in results. (Default: false)
includeLabels string A comma-separated list of IDs of labels to include in the labelInfo part of the response.
includePermissionsForView string Specifies which additional view's permissions to include in the response. Only 'published' is supported.
includeSubscribed boolean Whether to include changes outside the My Drive hierarchy in the result. When set to false, changes to files such as those in the Application Data folder or shared files which have not been added to My Drive are omitted from the result. (Default: true)
includeTeamDriveItems boolean Deprecated use includeItemsFromAllDrives instead. (Default: false)
maxResults integer Maximum number of changes to return. Acceptable values are 0 to 1000, inclusive. (Default: 100)
pageToken string The token for continuing a previous list request on the next page. This should be set to the value of 'nextPageToken' from the previous response or to the response from the getStartPageToken method.
spaces string A comma-separated list of spaces to query. Supported values are 'drive', 'appDataFolder' and 'photos'.
startChangeId long Deprecated - use pageToken instead.
supportsAllDrives boolean Whether the requesting application supports both My Drives and shared drives. (Default: false)
supportsTeamDrives boolean Deprecated use supportsAllDrives instead. (Default: false)
teamDriveId string Deprecated use driveId instead.

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.apps.readonly
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 response body with the following structure:

{
  "kind": "drive#changeList",
  "etag": etag,
  "selfLink": string,
  "nextPageToken": string,
  "newStartPageToken": string,
  "nextLink": string,
  "largestChangeId": long,
  "items": [
    changes Resource
  ]
}
Property name Value Description Notes
kind string This is always drive#changeList.
etag etag The ETag of the list.
nextPageToken string The page token for the next page of changes. This will be absent if the end of the changes list has been reached. If the token is rejected for any reason, it should be discarded, and pagination should be restarted from the first page of results.
largestChangeId long The current largest change ID.
items[] list The list of changes. If nextPageToken is populated, then this list may be incomplete and an additional page of results should be fetched.
newStartPageToken string The starting page token for future changes. This will be present only if the end of the current changes list has been reached.

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.Changes;
import com.google.api.services.drive.model.Change;
import com.google.api.services.drive.model.ChangeList;

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

// ...

public class MyClass {

  // ...

  /**
   * Retrieve a list of Change resources.
   *
   * @param service Drive API service instance.
   * @param startChangeId ID of the change to start retrieving subsequent
                          changes from or {@code null}.
   * @return List of Change resources.
   */
  private static List<Change> retrieveAllChanges(Drive service,
      Long startChangeId) throws IOException {
    List<Change> result = new ArrayList<Change>();
    Changes.List request = service.changes().list();

    if (startChangeId != null) {
      request.setStartChangeId(startChangeId);
    }
    do {
      try {
        ChangeList changes = request.execute();

        result.addAll(changes.getItems());
        request.setPageToken(changes.getNextPageToken());
      } catch (IOException e) {
        System.out.println("An error occurred: " + e);
        request.setPageToken(null);
      }
    } while (request.getPageToken() != null &&
             request.getPageToken().length() > 0);

    return result;
  }

  // ...

}

.NET

Uses the .NET client library.

using Google.Apis.Authentication;
using Google.Apis.Drive.v2;
using Google.Apis.Drive.v2.Data;

using System.Collections.Generic;
// ...

public class MyClass {

  // ...

  /// <summary>
  /// Retrieve a list of Change resources.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="startChangeId">
  /// ID of the change to start retrieving subsequent changes from or null.
  /// </param>
  /// <returns>List of Change resources.</returns>
  public static List<Change> retrieveAllChanges(DriveService service,
      String startChangeId) {
    List<Change> result = new List<Change>();
    ChangesResource.ListRequest request = service.Changes.List();

    if (!String.IsNullOrEmpty(startChangeId)) {
      request.StartChangeId = startChangeId;
    }
    do {
      try {
        ChangeList changes = request.Execute();

        result.AddRange(changes.Items);
        request.PageToken = changes.NextPageToken;
      } catch (Exception e) {
        Console.WriteLine("An error occurred: " + e.Message);
        request.PageToken = null;
      }
    } while (!String.IsNullOrEmpty(request.PageToken));
    return result;
  }

  // ...
}

PHP

Uses the PHP client library.

/**
 * Retrieve a list of Change resources.
 *
 * @param Google_Service_Drive $service Drive API service instance.
 * @param String $startChangeId ID of the change to start retrieving subsequent
 *     changes from or NULL.
 * @return Array List of Google_Service_Drive_Change resources.
 */
function retrieveAllChanges($service, $startChangeId = NULL) {
  $result = array();
  $pageToken = NULL;

  do {
    try {
      $parameters = array();
      if ($startChangeId) {
        $parameters['startChangeId'] = $startChangeId;
      }
      if ($pageToken) {
        $parameters['pageToken'] = $pageToken;
      }
      $changes = $service->changes->listChanges($parameters);

      $result = array_merge($result, $changes->getItems());
      $pageToken = $changes->getNextPageToken();
    } catch (Exception $e) {
      print "An error occurred: " . $e->getMessage();
      $pageToken = NULL;
    }
  } while ($pageToken);
  return $result;
}

Python

Uses the Python client library.

from apiclient import errors
# ...

def retrieve_all_changes(service, start_change_id=None):
  """Retrieve a list of Change resources.

  Args:
    service: Drive API service instance.
    start_change_id: ID of the change to start retrieving subsequent changes
                     from or None.
  Returns:
    List of Change resources.
  """
  result = []
  page_token = None
  while True:
    try:
      param = {}
      if start_change_id:
        param['startChangeId'] = start_change_id
      if page_token:
        param['pageToken'] = page_token
      changes = service.changes().list(**param).execute()

      result.extend(changes['items'])
      page_token = changes.get('nextPageToken')
      if not page_token:
        break
    except errors.HttpError, error:
      print 'An error occurred: %s' % error
      break
  return result

JavaScript

Uses the JavaScript client library.

/**
 * Retrieve a list of Change resources.
 *
 * @param {Function} callback Function to call when the request is complete.
 * @param {String} startChangeId ID of the change to start retrieving subsequent
 *                               changes from or {@code null}.
 *
 */
function retrieveAllChanges(callback, startChangeId) {
  var retrievePageOfChanges = function(request, result) {
    request.execute(function(resp) {
      result = result.concat(resp.items);
      var nextPageToken = resp.nextPageToken;
      if (nextPageToken) {
        request = gapi.client.drive.changes.list({
          'pageToken': nextPageToken
        });
        retrievePageOfChanges(request, result);
      } else {
        callback(result);
      }
    });
  }
  var initialRequest;
  if (startChangeId) {
    initialRequest = gapi.client.drive.changes.list({
      'startChangeId' : startChangeId
    });
  } else {
    initialRequest = gapi.client.drive.changes.list();
  }
  retrievePageOfChanges(initialRequest, []);
}

Go

Uses the Go client library.

import (
  "google.golang.org/drive/v2"
  "fmt"
)

// AllChanges fetches all changes after a starting change
func AllChanges(d *drive.Service,
    startChangeId string) ([]*drive.Change, error) {
  var cs []*drive.Change
  pageToken := ""
  for {
    q := d.Changes.List()
    // If we have a pageToken set, apply it to the query
    if pageToken != "" {
      q = q.PageToken(pageToken)
    }
    r, err := q.Do()
    if err != nil {
      fmt.Printf("An error occurred: %v\n", err)
      return cs, err
    }
    cs = append(cs, r.Items...)
    pageToken = string(r.NextPageToken)
    if pageToken == "" {
      break
    }
  }
  return cs, nil
}

Objective-C

Uses the Objective-C client library.

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

+ (void)retrieveAllChangesWithService:(GTLServiceDrive *)service
                        startChangeId:(long long)startChangeId
                      completionBlock:(void (^)(NSArray *, NSError *))completionBlock {
  // The service can be set to automatically fetch all pages of the result. More information
  // can be found on <a href="https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Result_Pages">https://code.google.com/p/google-api-objectivec-client/wiki/Introduction#Result_Pages</a>.
  service.shouldFetchNextPages = YES;

  GTLQueryDrive *query = [GTLQueryDrive queryForChangesList];
  if (startChangeId != -1) {
    query.startChangeId =  startChangeId;
  }
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveChangeList *changes,
                            NSError *error) {
          if (error == nil) {
            completionBlock(changes.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.