Cil*_*nco 5 push-notification google-drive-api
从 Drive SDK v3 开始,我们可以在文件发生更改时从 Google Drive接收推送通知。目前我正在使用 Python 开发 Drive 应用程序,我希望收到此类通知。我真的需要一个网络服务器,或者我可以用套接字或类似的东西来实现它吗?
我知道我可以通过轮询changes.list方法来获得更改,但由于 API 调用太多,我想避免这种情况。如果文件已更改,是否有更好的方法来获得通知?
编辑:我捕获了我的网络流量并看到原始的 Windows 版 Google Drive 客户端使用推送通知。因此,在某种程度上,必须可以在桌面应用程序中获得推送通知,但这可能是某种我们无法与当前 API 一起使用的Google 魔法吗?
对于需要跟踪文件更改的Google 云端硬盘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')
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
628 次 |
| 最近记录: |