Python receives notification using Google Drive

From the SDK v3 disc, we can receive push notifications from Google Drive whenever the file has been modified. I'm currently working on a Drive app in Python, and I would like to receive such notifications. Do I really need a web server for this, or can I implement this, perhaps with a socket or something similar?

I know that I can get the changes by polling the changes.list method , but I want to avoid this due to the large number of API calls. Maybe the best way to get information if the file has changed?

EDIT . I grabbed my web traffic and saw that the original Google Drive client for Windows was using push notifications. Thus, in some way, it should be possible to receive push notifications in a desktop application, but is it possible something like Google magic that we cannot use with the current API

+4
source share
1 answer

Google , , Changes collection , , . , , .

, Token .

# 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')
+2

Source: https://habr.com/ru/post/1648817/


All Articles