1

I developed a Python app to access GDrive, now I want to be notified in case any file is changed on gdrive. Specifically I'm interested in move / rename, remove, download and upload events. I see Google provide 2 tools:

  1. push notifications, but it looks like this is limited to notify changes for a specific file or dir, as outlined here.

  2. REST changes API, but AFAIU I am supposed to poll the google server every X seconds.

None of this is optimal for me, as I need global notifications about all filesystem-related events occurring on gdrive. Are there alternatives? I know DropBox supports this.

Community
  • 1
  • 1
Giampaolo Rodolà
  • 12,488
  • 6
  • 68
  • 60

1 Answers1

0

If your app only needs to be notified about changes, a better way as suggested in this blog is to let your app subscribe for changes to a user’s drive and get notified whenever changes occur.

Suppose your app is hosted on a server with my-host.com domain and push notifications should be delivered to an HTTPS web-hook https://my-host.com/notification:

String subscriptionId = UUID.randomUUID().toString();
  Channel request = new Channel()
    .setId(subscriptionId)
    .setType("web_hook")
    .setAddress("https://my-host.com/notification");
  drive.changes().watch(request).execute();

With this, as long as the subscription is active, Google Drive will trigger a web-hook callback at https://my-host.com/notification. The app can then query the change feed to catch up from the last synchronization point:

changes = service.changes().list()
    .setStartChangeId(lastChangeId).execute();

As mentioned further, if you are interested in using this new feature, please refer to the documentation. You can see push notifications in action with the Push Notifications Playground and view the source at Github.

Teyam
  • 7,686
  • 3
  • 15
  • 22
  • 1
    Push notifications have 2 issues: 1 they can't be used to watch all files (see: http://stackoverflow.com/questions/18144094/google-drive-sdk-push-notifications-watch-changes-on-all-files/18151189#18151189) 2 they expire after 1 day (this is less severe as I can register again). – Giampaolo Rodolà Sep 19 '16 at 13:08