push-notification - Python 接收 Google Drive 推送通知

标签 push-notification google-drive-api

自 Drive SDK v3 以来,我们能够收到 push notifications每当文件更改时从 Google Drive 中获取。目前我正在使用 Python 开发 Drive 应用程序,我希望收到这样的通知。我真的需要一个网络服务器吗?或者我可以用一个套接字或类似的东西来实现它吗?

我知道我可以通过轮询 changes.list 来获得更改。方法,但我想避免这种情况,因为 API 调用太多。如果文件已更改,是否有更好的方法来获取通知?

编辑 :我捕获了我的网络流量,发现原来的 Windows 版 Google Drive 客户端使用推送通知。所以在某种程度上,它必须有可能在桌面应用程序中获得推送通知,但这可能是某种我们无法与当前 API 一起使用的谷歌魔法吗

最佳答案

对于Google Drive需要跟踪文件更改的应用程序, Changes collection 提供了一种有效的方法来检测对所有文件的更改,包括与用户共享的文件。该集合通过提供每个文件的当前状态来工作,当且仅当文件自给定时间点以来发生了更改。

检索更改需要一个 pageToken 来指示从中获取更改的时间点。

# Begin with our last saved start token for this user or the
# current token from getStartPageToken()
page_token = saved_start_page_token;
while page_token is not None:
response = drive_service.changes().list(pageToken=page_token,
fields='*',
spaces='drive').execute()
for change in response.get('changes'):
# Process change
print 'Change found for file: %s' % change.get('fileId')
if 'newStartPageToken' in response:
# Last page, save this token for the next polling interval
saved_start_page_token = response.get('newStartPageToken')
page_token = response.get('nextPageToken')

关于push-notification - Python 接收 Google Drive 推送通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38531725/

相关文章:

ios - 从推送通知中将 JSON 有效负载数据转换为字符串

python - 无法将文件上传到 Google 云端硬盘

performance - 使用 Google Drive API 转移所有用户文件所有权的最有效流程

android - Google Drive REST API : java. lang.IllegalArgumentException:名称不能为空:null

android - 在 android 中使用 MQTT 的基本步骤

ios - 传入的富推送通知不会显示图像。 swift 4

android - 适用于 Android 的 Drive API 已损坏,对吧?

Android:如何使用 google-drive-sdk 访问电子表格?

android - 推送服务器如何知道将通知发送到哪里

spring - 使用 Spring Boot 的 Web API 通知