blob: 18c7a9d27a84ea5c0dfd7a051720f935efda1b8c [file] [log] [blame]
Joe Gregoriodeeb0202011-02-15 14:49:57 -05001#!/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
8Command-line application that sets the users
9current location.
10"""
11
12__author__ = 'jcgregorio@google.com (Joe Gregorio)'
13
14import httplib2
15
16from apiclient.discovery import build
17from oauth2client.file import Storage
18from oauth2client.client import OAuth2WebServerFlow
19from oauth2client.tools import run
Joe Gregorioa0a52e42011-02-17 17:13:26 -050020from apiclient.oauth import CredentialsInvalidError
Joe Gregoriodeeb0202011-02-15 14:49:57 -050021
22# Uncomment to get detailed logging
23#httplib2.debuglevel = 4
24
25
26def main():
Joe Gregorioa0a52e42011-02-17 17:13:26 -050027 credentials = Storage('latitude.dat').get()
Joe Gregorio9ce4b622011-02-17 15:32:11 -050028 if credentials is None or credentials.invalid:
Joe Gregoriodeeb0202011-02-15 14:49:57 -050029 flow = OAuth2WebServerFlow(
30 client_id='433807057907.apps.googleusercontent.com',
31 client_secret='jigtZpMApkRxncxikFpR+SFg',
32 scope='https://www.googleapis.com/auth/latitude',
33 user_agent='latitude-cmdline-sample/1.0',
34 xoauth_displayname='Latitude Client Example App')
35
36 credentials = run(flow, storage)
37
38 http = httplib2.Http()
39 http = credentials.authorize(http)
40
Joe Gregorio1ae3e742011-02-25 15:17:14 -050041 service = build("latitude", "v1", http=http)
Joe Gregoriodeeb0202011-02-15 14:49:57 -050042
43 body = {
44 "data": {
45 "kind": "latitude#location",
46 "latitude": 37.420352,
47 "longitude": -122.083389,
48 "accuracy": 130,
49 "altitude": 35
50 }
51 }
Joe Gregorioa0a52e42011-02-17 17:13:26 -050052 try:
Joe Gregorio1ae3e742011-02-25 15:17:14 -050053 print service.currentLocation().insert(body=body).execute()
Joe Gregorioa0a52e42011-02-17 17:13:26 -050054 except CredentialsInvalidError:
55 print 'Your credentials are no longer valid.'
56 print 'Please re-run this application to re-authorize.'
Joe Gregoriodeeb0202011-02-15 14:49:57 -050057
58if __name__ == '__main__':
59 main()