Skip to content Skip to sidebar Skip to footer

Gmail Api On Gae: Correctly Using Discovery.build_from_document()

I'm running a number of tasks on the GMail API and am getting the same error as described in this issue. To resolve it, I would like to implement the suggested solution. However I

Solution 1:

Turns out it was quite straight forward. I added following function:

def get_discovery_content():
  content = memcache.get('gmail_discovery')
  if content isnot None:
    return content
  else:
    h = httplib2.Http()
    for n inrange(0, 5):
      resp, content = h.request('https://www.googleapis.com/discovery/v1/apis/gmail/v1/rest?quotaUser=replimeapp')
      if resp.status == 200:
        memcache.add('gmail_discovery', content, 86400)
        return content  

Then I replaced this line:

service = discovery.build("gmail", "v1", http=http)

By this:

content = get_discovery_content()
service = discovery.build_from_document(content)

Works like a charm so far.

Post a Comment for "Gmail Api On Gae: Correctly Using Discovery.build_from_document()"