【发布时间】:2015-02-24 13:42:26
【问题描述】:
我在我的网站上集成了 google drive API 推送通知。 目前的工作:
- 在开发控制台、域等上注册 Web 应用程序...
- OAuth 授权
- 如果不存在则创建频道
- 设置 servlet 在发生更改时等待 google drive POST 请求
- Google 云端硬盘发生更改(上传或删除)
- Servlet 在更改发生时从 Google Drive 捕获 POST 请求
- 缓存消息:
{ "kind": "drive#change", "id": "8664", "selfLink": "https://www.googleapis.com/drive/v2/changes/8664"}
文件更改的 Google Drive API 表示:
{
"kind": "drive#change",
"id": long,
"fileId": string,
"selfLink": string,
"deleted": boolean,
"modificationDate": datetime,
"file": files Resource
}
如何获取fileId?为什么 Google Drive 不向我发送缺少的字段?我做错了什么?
手表换码:
service -> created ok
channelId -> UUID
channelType -> web_hook
channelAddress -> https://example.com/GoogleDriveWebhook (GoogleDriveWebhook is servlet)
public static Channel watchChange(Drive service, String channelId, String channelType, String channelAddress) {
Channel channel = new Channel();
channel.setId(channelId);
channel.setType(channelType);
channel.setAddress(channelAddress);
channel.setExpiration(new Date().getTime() + (600000 * 2));//20 min session for channel (test environment)
try {
return service.changes().watch(channel).execute();
} catch (IOException e) {
System.out.println("Something is wrong with instancing new channel");
e.printStackTrace();
}
return null;
}
...很明显,谷歌驱动器发送的应用程序捕获更改,我被卡住了请帮助!
【问题讨论】:
-
您在寻找什么样的缺失参数?请查看此页面以获取响应资源:developers.google.com/drive/web/push
-
谢谢我读了它,所以这个推送通知并没有真正告诉我什么文件被改变了,只通知我谷歌驱动器上的东西已经改变了?然后我尝试使用“Changes:get”API,参数:(Drive service,String changeId)我通过{“kind”:“drive#change”,“id”:“8664”, "selfLink": "googleapis.com/drive/v2/changes/8664"} id 像 String changedId 但我总是得到 "Change not found: 8754" 用于上传或删除
标签: java google-drive-api