android–Google Drive REST API Notifications不适用于app文件夹中的更改

android–Google Drive REST API Notifications不适用于app文件夹中的更改,第1张

概述根据文档,应该可以使用setSpaces(“appDataFolder”)注册更改我的应用程序的app文件夹的通知通道.但是,我在设置频道时只收到初始同步通知,但在我更改app文件夹中的内容时没有更改通知.如果我使用setSpaces(“驱动器”)或完全省略setSpaces()并在常规驱动器空间中更改某些内容,我

根据文档,应该可以使用setSpaces(“appDataFolder”)注册更改我的应用程序的app文件夹的通知通道.

但是,我在设置频道时只收到初始同步通知,但在我更改app文件夹中的内容时没有更改通知.

如果我使用setSpaces(“驱动器”)或完全省略setSpaces()并在常规驱动器空间中更改某些内容,我会收到更改通知.

我没有找到关于在app文件夹中查看更改的任何内容,所以我希望有人可以帮助我.

这就是我设置频道的方式,其中mDrive是com.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();

解决方法:

你有没有设置这个范围?确保您有足够广泛的范围来包含’appDataFolder’.我的意思是你应该能够从这里获得一些结果(从here开始):

/** * 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

此外,你在检查结果是否为空?你真的应该将Channel result = …行放在try {} catch(IOExeption e){}中,如果在这个例子中有一个(从here开始),则打印错误.

  /**   * Watch for all changes to a user's 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());}
总结

以上是内存溢出为你收集整理的android – Google Drive REST API Notifications不适用于app文件夹中的更改全部内容,希望文章能够帮你解决android – Google Drive REST API Notifications不适用于app文件夹中的更改所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120420.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存