blob: c0a629fb549b1fd3bdd8541373de2fb842273f58 [file] [log] [blame]
Joe Gregorio0802a172010-10-26 16:23:00 -04001#!/usr/bin/python2.4
2# -*- coding: utf-8 -*-
3#
Joe Gregorio88f699f2012-06-07 13:36:06 -04004# 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 Gregorio0802a172010-10-26 16:23:00 -040017
18"""Simple command-line example for Latitude.
19
20Command-line application that sets the users
21current location.
Joe Gregorio88f699f2012-06-07 13:36:06 -040022
23Usage:
24 $ python latitude.py
25
26You can also get help on all the command-line flags the program understands
27by running:
28
29 $ python latitude.py --help
30
31To get detailed log output run:
32
33 $ python latitude.py --logging_level=DEBUG
Joe Gregorio0802a172010-10-26 16:23:00 -040034"""
35
36__author__ = 'jcgregorio@google.com (Joe Gregorio)'
37
Joe Gregorio88f699f2012-06-07 13:36:06 -040038import sys
Joe Gregorio0802a172010-10-26 16:23:00 -040039
Joe Gregoriod2caecb2013-05-20 16:09:57 -040040from oauth2client import client
41from apiclient import sample_tools
Joe Gregorio88f699f2012-06-07 13:36:06 -040042
43def main(argv):
Joe Gregoriod2caecb2013-05-20 16:09:57 -040044 service, flags = sample_tools.init(
45 argv, 'latitude', 'v1', __doc__, __file__,
46 scope='https://www.googleapis.com/auth/latitude.all.best')
Joe Gregorio0802a172010-10-26 16:23:00 -040047
Joe Gregorio88f699f2012-06-07 13:36:06 -040048 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 Gregoriod2caecb2013-05-20 16:09:57 -040061 except client.AccessTokenRefreshError:
Joe Gregorio88f699f2012-06-07 13:36:06 -040062 print ("The credentials have been revoked or expired, please re-run"
63 "the application to re-authorize")
Joe Gregorio0802a172010-10-26 16:23:00 -040064
65if __name__ == '__main__':
Joe Gregorio88f699f2012-06-07 13:36:06 -040066 main(sys.argv)