blob: a4d29d2acaab97326186a12f7d25c972f3225675 [file] [log] [blame]
Joe Gregorio0802a172010-10-26 16:23:00 -04001#!/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
14
15from apiclient.discovery import build
16
17import httplib2
18import pickle
19
Joe Gregorio9ce4b622011-02-17 15:32:11 -050020from apiclient.discovery import build
21from apiclient.oauth import FlowThreeLegged
22from apiclient.ext.authtools import run
23from apiclient.ext.file import Storage
24
Joe Gregorio0802a172010-10-26 16:23:00 -040025# Uncomment to get detailed logging
26# httplib2.debuglevel = 4
27
Joe Gregorioaf276d22010-12-09 14:26:58 -050028
Joe Gregorio0802a172010-10-26 16:23:00 -040029def main():
Joe Gregoriofffa7d72011-02-18 17:20:39 -050030 storage = Storage('latitude.dat')
31 credentials = storage.get()
Joe Gregorioa0a52e42011-02-17 17:13:26 -050032 if credentials is None or credentials.invalid == True:
Joe Gregorio9ce4b622011-02-17 15:32:11 -050033 auth_discovery = build("latitude", "v1").auth_discovery()
34 flow = FlowThreeLegged(auth_discovery,
35 # You MUST have a consumer key and secret tied to a
36 # registered domain to use the latitude API.
37 #
38 # https://www.google.com/accounts/ManageDomains
39 consumer_key='REGISTERED DOMAIN NAME',
40 consumer_secret='KEY GIVEN DURING REGISTRATION',
41 user_agent='google-api-client-python-latitude/1.0',
42 domain='REGISTERED DOMAIN NAME',
43 scope='https://www.googleapis.com/auth/latitude',
44 xoauth_displayname='Google API Latitude Example',
45 location='current',
46 granularity='city'
47 )
48
Joe Gregoriofffa7d72011-02-18 17:20:39 -050049 credentials = run(flow, storage)
Joe Gregorio0802a172010-10-26 16:23:00 -040050
51 http = httplib2.Http()
52 http = credentials.authorize(http)
53
Joe Gregorio1ae3e742011-02-25 15:17:14 -050054 service = build("latitude", "v1", http=http)
Joe Gregorio0802a172010-10-26 16:23:00 -040055
56 body = {
57 "data": {
Joe Gregorioaf276d22010-12-09 14:26:58 -050058 "kind": "latitude#location",
59 "latitude": 37.420352,
60 "longitude": -122.083389,
61 "accuracy": 130,
62 "altitude": 35
Joe Gregorio0802a172010-10-26 16:23:00 -040063 }
64 }
Joe Gregorio1ae3e742011-02-25 15:17:14 -050065 print service.currentLocation().insert(body=body).execute()
Joe Gregorio0802a172010-10-26 16:23:00 -040066
67if __name__ == '__main__':
68 main()