Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
| 4 | # Copyright 2010 Google Inc. All Rights Reserved. |
| 5 | |
| 6 | """Simple command-line example for Latitude. |
| 7 | |
| 8 | Command-line application that sets the users |
| 9 | current location. |
| 10 | """ |
| 11 | |
| 12 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 13 | |
| 14 | |
| 15 | from apiclient.discovery import build |
| 16 | |
| 17 | import httplib2 |
| 18 | import pickle |
| 19 | |
Joe Gregorio | 9ce4b62 | 2011-02-17 15:32:11 -0500 | [diff] [blame] | 20 | from apiclient.discovery import build |
| 21 | from apiclient.oauth import FlowThreeLegged |
| 22 | from apiclient.ext.authtools import run |
| 23 | from apiclient.ext.file import Storage |
| 24 | |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 25 | # Uncomment to get detailed logging |
| 26 | # httplib2.debuglevel = 4 |
| 27 | |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 28 | |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 29 | def main(): |
Joe Gregorio | 9ce4b62 | 2011-02-17 15:32:11 -0500 | [diff] [blame] | 30 | credentials = Storage('latitude.dat').get() |
Joe Gregorio | a0a52e4 | 2011-02-17 17:13:26 -0500 | [diff] [blame] | 31 | if credentials is None or credentials.invalid == True: |
Joe Gregorio | 9ce4b62 | 2011-02-17 15:32:11 -0500 | [diff] [blame] | 32 | auth_discovery = build("latitude", "v1").auth_discovery() |
| 33 | flow = FlowThreeLegged(auth_discovery, |
| 34 | # You MUST have a consumer key and secret tied to a |
| 35 | # registered domain to use the latitude API. |
| 36 | # |
| 37 | # https://www.google.com/accounts/ManageDomains |
| 38 | consumer_key='REGISTERED DOMAIN NAME', |
| 39 | consumer_secret='KEY GIVEN DURING REGISTRATION', |
| 40 | user_agent='google-api-client-python-latitude/1.0', |
| 41 | domain='REGISTERED DOMAIN NAME', |
| 42 | scope='https://www.googleapis.com/auth/latitude', |
| 43 | xoauth_displayname='Google API Latitude Example', |
| 44 | location='current', |
| 45 | granularity='city' |
| 46 | ) |
| 47 | |
| 48 | credentials = run(flow, 'latitude.dat') |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 49 | |
| 50 | http = httplib2.Http() |
| 51 | http = credentials.authorize(http) |
| 52 | |
| 53 | p = build("latitude", "v1", http=http) |
| 54 | |
| 55 | body = { |
| 56 | "data": { |
Joe Gregorio | af276d2 | 2010-12-09 14:26:58 -0500 | [diff] [blame] | 57 | "kind": "latitude#location", |
| 58 | "latitude": 37.420352, |
| 59 | "longitude": -122.083389, |
| 60 | "accuracy": 130, |
| 61 | "altitude": 35 |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 62 | } |
| 63 | } |
| 64 | print p.currentLocation().insert(body=body).execute() |
| 65 | |
| 66 | if __name__ == '__main__': |
| 67 | main() |