Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 1 | #!/usr/bin/python2.4 |
| 2 | # -*- coding: utf-8 -*- |
| 3 | # |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 4 | # Copyright (C) 2012 Google Inc. |
| 5 | # |
| 6 | # Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | # you may not use this file except in compliance with the License. |
| 8 | # You may obtain a copy of the License at |
| 9 | # |
| 10 | # http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | # |
| 12 | # Unless required by applicable law or agreed to in writing, software |
| 13 | # distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | # See the License for the specific language governing permissions and |
| 16 | # limitations under the License. |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 17 | |
| 18 | """Simple command-line example for Latitude. |
| 19 | |
| 20 | Command-line application that sets the users |
| 21 | current location. |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 22 | |
| 23 | Usage: |
| 24 | $ python latitude.py |
| 25 | |
| 26 | You can also get help on all the command-line flags the program understands |
| 27 | by running: |
| 28 | |
| 29 | $ python latitude.py --help |
| 30 | |
| 31 | To get detailed log output run: |
| 32 | |
| 33 | $ python latitude.py --logging_level=DEBUG |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 34 | """ |
| 35 | |
| 36 | __author__ = 'jcgregorio@google.com (Joe Gregorio)' |
| 37 | |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 38 | import sys |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 39 | |
Joe Gregorio | d2caecb | 2013-05-20 16:09:57 -0400 | [diff] [blame^] | 40 | from oauth2client import client |
| 41 | from apiclient import sample_tools |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 42 | |
| 43 | def main(argv): |
Joe Gregorio | d2caecb | 2013-05-20 16:09:57 -0400 | [diff] [blame^] | 44 | service, flags = sample_tools.init( |
| 45 | argv, 'latitude', 'v1', __doc__, __file__, |
| 46 | scope='https://www.googleapis.com/auth/latitude.all.best') |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 47 | |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 48 | try: |
| 49 | body = { |
| 50 | "data": { |
| 51 | "kind": "latitude#location", |
| 52 | "latitude": 37.420352, |
| 53 | "longitude": -122.083389, |
| 54 | "accuracy": 130, |
| 55 | "altitude": 35 |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | print service.currentLocation().insert(body=body).execute() |
| 60 | |
Joe Gregorio | d2caecb | 2013-05-20 16:09:57 -0400 | [diff] [blame^] | 61 | except client.AccessTokenRefreshError: |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 62 | print ("The credentials have been revoked or expired, please re-run" |
| 63 | "the application to re-authorize") |
Joe Gregorio | 0802a17 | 2010-10-26 16:23:00 -0400 | [diff] [blame] | 64 | |
| 65 | if __name__ == '__main__': |
Joe Gregorio | 88f699f | 2012-06-07 13:36:06 -0400 | [diff] [blame] | 66 | main(sys.argv) |