~ubuntu-branches/ubuntu/utopic/python-googleapi/utopic

« back to all changes in this revision

Viewing changes to samples/latitude/latitude.py

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2013-08-31 21:02:56 UTC
  • mfrom: (0.1.1)
  • Revision ID: package-import@ubuntu.com-20130831210256-z8qqru6lhi7azqqr
Tags: 1.2-1
Initial release (closes: #620602).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python2.4
 
2
# -*- coding: utf-8 -*-
 
3
#
 
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.
 
17
 
 
18
"""Simple command-line example for Latitude.
 
19
 
 
20
Command-line application that sets the users
 
21
current location.
 
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
 
34
"""
 
35
 
 
36
__author__ = 'jcgregorio@google.com (Joe Gregorio)'
 
37
 
 
38
import sys
 
39
 
 
40
from oauth2client import client
 
41
from apiclient import sample_tools
 
42
 
 
43
def main(argv):
 
44
  service, flags = sample_tools.init(
 
45
      argv, 'latitude', 'v1', __doc__, __file__,
 
46
      scope='https://www.googleapis.com/auth/latitude.all.best')
 
47
 
 
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
 
 
61
  except client.AccessTokenRefreshError:
 
62
    print ("The credentials have been revoked or expired, please re-run"
 
63
      "the application to re-authorize")
 
64
 
 
65
if __name__ == '__main__':
 
66
  main(sys.argv)