Martijn Nosyncerror
Martijn Nosyncerror

Reputation: 192

Google Drive API - Changes: list. Getting the original ID of a deleted file

When trying to detect deleted objects using the Changes: list feed, I noticed that the id value is incorrect making it impossible for me to detect which file was deleted. Example:

Make new testfile : This is a test file

public 'title' => string 'This is a test' (length=14)
public 'id' => string '1wUFHe3DfU1mJnyqlIgAYSvMrIy8F91-7rZyAPFsyVpg' (length=44)

Now when I delete this file the first entry for a deleted change is:

public 'deleted' => boolean true
protected 'fileType' => string 'Google_Service_Drive_DriveFile' (length=30)
protected 'fileDataType' => string '' (length=0)
public 'fileId' => string '1_8Cvirw71AY0HQoaNwSMP3TlcIFAhpZikVfOrXFZCLo'        (length=44)
public 'id' => string '3612' (length=4)
public 'kind' => string 'drive#change' (length=12)
public 'modificationDate' => string '2013-12-23T10:55:45.340Z' (length=24)
public 'selfLink' => string 'https://www.googleapis.com/drive/v2/changes/3612' (length=48)
  protected 'modelData' => 
    array (size=0)
      empty
  protected 'processed' => 
    array (size=0)
      empty

None of the identifiers (fileId and id) equal the id from the file 'This is a test file'. I read in the API documentation that the results are from the bottom up, but non of the deleted changes contain my original file id.

How would I know which file was deleted?

EDIT: I've created a video showing my problems, steps

https://www.youtube.com/watch?v=hh2ARFdxWGk

Sorry for the poor quality, I used a bad screen recording tool

Upvotes: 4

Views: 1977

Answers (2)

Jay Lee
Jay Lee

Reputation: 13528

You might try using the Apps Activity API instead of Changes. I just tested with Apps Activity API and both trash and emptyTrash show as events. The API Explorer gives you an idea of how to achieve this.

Upvotes: 3

KRR
KRR

Reputation: 4927

The first thing is that the entries in the changes feed are ordered in ascending chronological order. That is, the oldest changes show up first. So check the last enries in the response.

You can also try this in API explorer. Get the first set of list and for getting the latest changes you can either get the nextPageToken from the response or the largestChangeId from the last change in the list and get the next set of changes.

Hope that helps!

Upvotes: 1

Related Questions