def main(): signal.alarm(47) storage = Storage('latitude.dat') credentials = storage.get() if credentials is None or credentials.invalid == True: auth_discovery = build("latitude", "v1").auth_discovery() flow = FlowThreeLegged( auth_discovery, # You MUST have a consumer key and secret tied to a # registered domain to use the latitude API. # # https://www.google.com/accounts/ManageDomains consumer_key='west.spy.net', consumer_secret='kF52E2QkcMYeWI5JBxUdqHkE', user_agent='google-api-client-python-latitude/1.0', domain='west.spy.net', scope='https://www.googleapis.com/auth/latitude', xoauth_displayname='Google API Latitude Example', location='all', granularity='best') credentials = run(flow, storage) http = httplib2.Http() http = credentials.authorize(http) service = build("latitude", "v1", http=http) more = True max_time = "" args = {'max_results': '1000', 'granularity': 'best'} # See if we're picking up from somewhere... try: lastKey = list( DB.view('_all_docs', limit=1, descending=True, startkey='9'))[0].id args['min_time'] = lastKey print "Resuming since", lastKey except IndexError: print "Not resuming." while more: r = service.location().list(**args).execute()['items'] store(r) more = len(r) == 1000 print "Got %d records from %s - %s" % (len(r), ts(r[-1]), ts(r[0])) args['max_time'] = r[-1]['timestampMs']
def main(): storage = Storage('latitude.dat') credentials = storage.get() if credentials is None or credentials.invalid == True: auth_discovery = build("latitude", "v1").auth_discovery() flow = FlowThreeLegged( auth_discovery, # You MUST have a consumer key and secret tied to a # registered domain to use the latitude API. # # https://www.google.com/accounts/ManageDomains consumer_key='REGISTERED DOMAIN NAME', consumer_secret='KEY GIVEN DURING REGISTRATION', user_agent='google-api-client-python-latitude/1.0', domain='REGISTERED DOMAIN NAME', scope='https://www.googleapis.com/auth/latitude', xoauth_displayname='Google API Latitude Example', location='current', granularity='city') credentials = run(flow, storage) http = httplib2.Http() http = credentials.authorize(http) service = build("latitude", "v1", http=http) body = { "data": { "kind": "latitude#location", "latitude": 37.420352, "longitude": -122.083389, "accuracy": 130, "altitude": 35 } } print service.currentLocation().insert(body=body).execute()