gpt4 book ai didi

android - Google Drive REST API 通知不适用于应用程序文件夹中的更改

转载 作者:太空宇宙 更新时间:2023-11-03 11:06:05 25 4
gpt4 key购买 nike

根据文档,应该可以使用 setSpaces("appDataFolder") 为我的应用程序的应用程序文件夹的更改注册一个通知 channel 。

但是,我只在设置 channel 时收到初始 sync 通知,但在我更改应用程序文件夹中的内容时没有 change 通知。

如果我使用 setSpaces("drive") 或完全省略 setSpaces() 并更改常规驱动器空间中的某些内容,我会收到 change 通知没问题。

我在app文件夹中没有找到任何关于watching for changes的信息,所以我希望这里有人能帮助我。

这就是我设置 channel 的方式,其中 mDrivecom.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 通知不适用于应用程序文件夹中的更改,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33485557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com