Drive REST API notifications not working for changes to application folder

According to the documentation, it should be possible to register the notification channel for changes in the application folder of my application using setSpaces("appDataFolder").

However, I get only the initial notification syncwhen setting up the channel, but not changenotifications when I change something in the application folder.

If I use setSpaces("drive")or even omit setSpaces()it and change something in the normal disk space, I get notifications changein order.

I did not find anything about viewing the changes in the application folder, so I hope someone here can help me.

This is how I installed the channel, where mDriveis the fully initialized and resolved instancecom.google.api.services.drive.Drive

channelId = UUID.randomUUID().toString();
channelExpiration = System.currentTimeMillis() + CHANNEL_LIVETIME_MILLIS;
Channel channel = new Channel();
channel.setType("web_hook");
channel.setId(channelId);
channel.setAddress(DRIVE_API_CALLBACK_RECEIVER_URL);
channel.setToken("...");
channel.setExpiration(channelExpiration);
Channel result = mDrive.changes().watch(channel).setSpaces("appDataFolder").execute();
+4
1

, ? , "appDataFolder". , ( ):

/**
 * Print metadata for the Application Data folder.
 *
 * @param service Drive API service instance.
 */
private static void printApplicationDataFolderMetadata(Drive service) {
  try {
    File file = service.files().get("appfolder").execute();

    System.out.println("Id: " + file.getId());
    System.out.println("Title: " + file.getTitle());
  } catch (IOException e) {
    System.out.println("An error occured: " + e);
  }
}

, . , drive.appfolder

https://www.googleapis.com/auth/drive.appfolder

, null? Channel result =... try {} catch(IOExeption e) {} , ( ).

  /**
   * Watch for all changes to a user Drive.
   *
   * @param service Drive API service instance.
   * @param channelId Unique string that identifies this channel.
   * @param channelType Type of delivery mechanism used for this channel.
   * @param channelAddress Address where notifications are delivered.
   * @return The created channel if successful, {@code null} otherwise.
   */
  private static Channel watchChange(Drive service, String channelId,
      String channelType, String channelAddress) {
    Channel channel = new Channel();
    channel.setId(channelId);
    channel.setType(channelType);
    channel.setAddress(channelAddress);
    try {
      return service.changes().watch(channel).execute();
    } catch (IOException e) {
      e.printStackTrace();
      // ADD A LOG OR PRINT STATEMENT HERE 
      Log.e("DRIVEAPI", "Error: " + e.toString())
    }
    return null;
  }

:

channelId = UUID.randomUUID().toString();
channelExpiration = System.currentTimeMillis() + CHANNEL_LIVETIME_MILLIS;
Channel channel = new Channel();
channel.setType("web_hook");
channel.setId(channelId);
channel.setAddress(DRIVE_API_CALLBACK_RECEIVER_URL);
channel.setToken("...");
channel.setExpiration(channelExpiration);
try {
    Channel result = mDrive.changes().watch(channel).setSpaces("appDataFolder").execute();
    if(result != null) {
        // do whatever you want with result Channel
    } else {
        Log.e("DRIVEAPI", "Error: result is null for some reason!");
    }
} catch (IOException e) {
    e.printStackTrace()
    Log.e("DRIVEAPI", "Error: " + e.toString());
}
0

Source: https://habr.com/ru/post/1614191/


All Articles