title: How to properly watch for gmail push notifications
body: <p>I don't understand how to properly watch for gmail push notifications (also i know nothing about the web in terms of coding).</p>
  <p>Google give this tutorial page: <a href="https://developers.google.com/gmail/api/guides/push" rel="nofollow noreferrer">https://developers.google.com/gmail/api/guides/push</a></p>
  <p>What i did so far:</p>
  <ul>
  <li>Prerequisites : DONE</li>
  <li>Create a topic : DONE</li>
  <li>Create a subscription : DONE</li>
  <li>Grant publish rights on your topic : DONE</li>
  <li>watch() method works and gives this result: <code>{'historyId': '714707', 'expiration': '1618824687477'}</code></li>
  </ul>
  <p>So far everything works fine, but my knowledge stops here. It seems to me that i have to implement some kind of infinite while loop on the watch method, to check for <code>historyId</code> changes. But if so, why would there be a <code>stop()</code> method on the <code>watch()</code> method, and also why would there be a <code>expiration</code> field on the watch result ?
  What should i do from there ?</p>
  <p>Here is my implementation so far:</p>
  <pre><code>from __future__ import print_function
  import os.path
  from googleapiclient.discovery import build
  from google_auth_oauthlib.flow import InstalledAppFlow
  from google.auth.transport.requests import Request
  from google.oauth2.credentials import Credentials
  
  
  SCOPES = ['https://mail.google.com/']
  MY_TOPIC_NAME = 'my/toppic/name'
  
  creds = None
  if os.path.exists('token.json'):
          creds = Credentials.from_authorized_user_file('token.json', SCOPES)
  if not creds or not creds.valid:
          if creds and creds.expired and creds.refresh_token:
                  creds.refresh(Request())
  else:
          flow = InstalledAppFlow.from_client_secrets_file('./my_creds.json', SCOPES)
          creds = flow.run_local_server(port=0)
  with open('token.json', 'w') as token:
          token.write(creds.to_json())
  
  
  
  gmail = build('gmail', 'v1', credentials=creds)
  request = {'labelIds': ['INBOX'],'topicName': MY_TOPIC_NAME}
  gmail.users().watch(userId='me', body=request).execute()
  </code></pre>