Google Drive SDK

Changes: get

Requires authorization

Gets a specific change. Try it now or see an example.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
changeId string The ID of the change.

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
https://www.googleapis.com/auth/drive.apps.readonly

Request body

Do not supply a request body with this method.

Response

If successful, this method returns a Changes 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.Change;
import com.google.api.services.drive.model.File;

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

public class MyClass {

  // ...

  /**
   * Print a single Change resource information.
   *
   * @param service Drive API service instance.
   * @param changeId ID of the Change resource to retrieve.
   */
  private static void printChange(Drive service, String changeId) {
    try {
      Change change = service.changes().get(changeId).execute();

      System.out.println("Changed file ID: " + change.getFileId());
      if (change.getDeleted()) {
        System.out.println("File has been deleted");
      } else {
        File changedFile = change.getFile();
        System.out.println("Changed file Title: " + changedFile.getTitle());
      }
    } 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>
  /// Print a single Change resource information.
  /// </summary>
  /// <param name="service">Drive API service instance.</param>
  /// <param name="changeId">ID of the Change resource to retrieve.</param>
  public static void PrintChange(DriveService service, String changeId) {
    try {
      Change change = service.Changes.Get(changeId).Fetch();

      Console.WriteLine("Changed file ID: " + change.FileId);
      if (change.Deleted.HasValue && (bool)change.Deleted) {
        Console.WriteLine("File has been deleted");
      } else {
        File changedFile = change.File;
        Console.WriteLine("Changed file Title: " + changedFile.Title);
      }
    } catch (Exception e) {
      Console.WriteLine("An error occurred: " + e.Message);
    }
  }

  // ...
}

PHP

Uses the PHP client library

/**
 * Print a single Change resource information.
 *
 * @param Google_DriveService $service Drive API service instance.
 * @param String $changeId ID of the Change resource to retrieve.
 */
function printChange($service, $changeId) {
  try {
    $change = $service->changes->get($changeId);

    print "Changed file ID: " . $change->getFileId();
    if ($change->getDeleted()) {
      print "File has been deleted";
    } else {
      $changedFile = $change->getFile();
      print "Changed file Title: " . $changedFile->getTitle();
    }
  } catch (Exception $e) {
    print "An error occurred: " . $e->getMessage();
  }
}

Python

Uses the Python client library

from apiclient import errors
# ...

def print_change(service, change_id):
  """Print a single Change resource information.

  Args:
    service: Drive API service instance.
    change_id: ID of the Change resource to retrieve.
  """
  try:
    change = service.changes().get(changeId=change_id).execute()

    print 'Changed file ID: %s' % change['fileId']
    if change['deleted']:
      print 'File has been deleted'
    else:
      file = change['file']
      print 'Changed file Title: %s' % file['title']
  except errors.HttpError, error:
    print 'An error occurred: %s' % error

Ruby

Uses the Ruby client library

##
# Print a single Change resource information
#
# @param [Google::APIClient] client
#   Authorized client instance
# @param [String] change_id
#   ID of the Change resource to retrieve
# @return nil
def print_change(client, change_id)
  drive = client.discovered_api('drive', 'v2')
  result = client.execute(
    :api_method => drive.changes.get,
    :parameters => { 'changeId' => change_id })
  if result.status == 200
    change = result.data
    puts "Changed file ID: #{change.file_id}"
    if change.deleted
      puts "File has been deleted"
    else
      file = change.file
      puts "Changed file Title: #{file.title}"

    end
  else
    puts "An error occurred: #{result.data['error']['message']}"
  end
end

JavaScript

Uses the JavaScript client library

/**
 * Print a single Change resource information.
 *
 * @param {String} changeId ID of the Change resource to retrieve.
 */
function printChange(changeId) {
  var request = gapi.client.drive.changes.get({
    'changeId': changeId
  });
  request.execute(function(resp) {
    if (resp.deleted) {
      console.log('File has been deleted');
    } else {
      var file = resp.file;
      console.log('Changed file Title: ' + file.title);
    }
  });
}

Go

Uses the Go client library

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

// PrintChange fetches and displays the change with the passed changeId
func PrintChange(d *drive.Service, changeId string) error {
  c, err := d.Changes.Get(changeId).Do()
  if err != nil {
    fmt.Printf("An error occurred: %v\n", err)
    return err
  }
  fmt.Printf("Changed file ID: %v\n", c.FileId)
  if c.Deleted {
    fmt.Printf("File has been deleted\n")
  } else {
    fmt.Printf("Changed file Title: %v\n",  c.File.Title)
  }
  return nil
}

Objective-C

Uses the Objective-C client library

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

+ (void)printChangeWithService:(GTLServiceDrive *)service
                      changeId:(NSString *)changeId {
  GTLQueryDrive *query = [GTLQueryDrive queryForChangesGetWithChangeId:changeId];
  // queryTicket can be used to track the status of the request.
  GTLServiceTicket *queryTicket =
    [service executeQuery:query
        completionHandler:^(GTLServiceTicket *ticket, GTLDriveChange *change,
                            NSError *error) {
          if (error == nil) {
            NSLog(@"Current user name: %@", change.fileId);

            if ([change.deleted boolValue]) {
              NSLog(@"File has been deleted");
            } else {
              GTLDriveFile *changedFile = change.file;
              NSLog(@"Changed file Title: %@", changedFile.title);
            }
          } else {
            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.