I'm using the Google Drive API v3 and the Go SDK to monitor new and removed files on my drive. I've looked over the Google Drive API v3 documentation and they provide 2 file properties that seem like they would allow one to determine if a file was deleted.
After I remove the file, the file appears in the change list, but both properties are false.
What attribute, service, or call can I use to determine if something has been removed?
package main
import (
"fmt"
"strconv"
"google.golang.org/api/drive/v3"
)
func main() {
// More code is required to setup the service, but I didn't include it.
srv := new(drive.Service)
//......
token, _ := srv.Changes.GetStartPageToken().Do()
// ..... some time passes
// I right click file and select "Remove" from google drive using web app.
// Now I list any changes in MyDrive
changes, _ := srv.Changes.List(token.StartPageToken).IncludeRemoved(false).RestrictToMyDrive(true).Do()
for _, c := range changes.Changes {
fmt.Println("File name: " + c.File.Name) // I get the expected file name
fmt.Println("Trash: " + strconv.FormatBool(c.File.Trashed)) //false
fmt.Println("Removed: " + strconv.FormatBool(c.Removed)) //false
fmt.Println("ExplicitlyTrashed: " + strconv.FormatBool(c.File.ExplicitlyTrashed)) //false
}
}
You should set IncludeRemoved
to true and RestrictToMyDrive
to false - at least while you're investigating this missing changes problem. The doc says:
includeRemoved boolean Whether to include changes indicating that items have left the view of the changes list, for example by deletion or lost access. (Default: true)
and
restrictToMyDrive boolean Whether to restrict the results to changes inside the My Drive hierarchy. This omits changes to files such as those in the Application Data folder or shared files which have not been added to My Drive. (Default: false)
Edit 10 Dec: Your issue is caused by the fact that if the file is trashed then the change resource will NOT contain a file resource. You should check the change resource for the removed
flag and not check for any file properties because the file resource won't be there in the change:
removed boolean Whether the file has been removed from the view of the changes list, for example by deletion or lost access.
file nested object The updated state of the file. Present if the file has not been removed.
The info above is from the Drive V3 reference guide > changes page