Joe Gregorio | deeb020 | 2011-02-15 14:49:57 -0500 | [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 | import httplib2 |
| 15 | |
| 16 | from apiclient.discovery import build |
| 17 | from oauth2client.file import Storage |
| 18 | from oauth2client.client import OAuth2WebServerFlow |
| 19 | from oauth2client.tools import run |
| 20 | |
| 21 | # Uncomment to get detailed logging |
| 22 | #httplib2.debuglevel = 4 |
| 23 | |
| 24 | |
| 25 | def main(): |
| 26 | storage = Storage('latitude.dat') |
| 27 | credentials = storage.get() |
| 28 | |
| 29 | if not credentials: |
| 30 | flow = OAuth2WebServerFlow( |
| 31 | client_id='433807057907.apps.googleusercontent.com', |
| 32 | client_secret='jigtZpMApkRxncxikFpR+SFg', |
| 33 | scope='https://www.googleapis.com/auth/latitude', |
| 34 | user_agent='latitude-cmdline-sample/1.0', |
| 35 | xoauth_displayname='Latitude Client Example App') |
| 36 | |
| 37 | credentials = run(flow, storage) |
| 38 | |
| 39 | http = httplib2.Http() |
| 40 | http = credentials.authorize(http) |
| 41 | |
| 42 | p = build("latitude", "v1", http=http) |
| 43 | |
| 44 | body = { |
| 45 | "data": { |
| 46 | "kind": "latitude#location", |
| 47 | "latitude": 37.420352, |
| 48 | "longitude": -122.083389, |
| 49 | "accuracy": 130, |
| 50 | "altitude": 35 |
| 51 | } |
| 52 | } |
| 53 | print p.currentLocation().insert(body=body).execute() |
| 54 | |
| 55 | if __name__ == '__main__': |
| 56 | main() |