【问题标题】:Python receive Google Drive push notificationPython 接收 Google Drive 推送通知
【发布时间】:2016-07-22 16:53:59
【问题描述】:

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

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

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

【问题讨论】:

    标签: push-notification google-drive-api


    【解决方案1】:

    对于需要跟踪文件更改的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')
    

    【讨论】:

    • 我的意思是 轮询 changes.list 方法,我想避免这种情况,因为循环中有这么多 API 调用。
    猜你喜欢
    • 2017-05-13
    • 2016-07-31
    • 1970-01-01
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-23
    相关资源
    最近更新 更多