blob: 1dd1c390d87c734f5519701013068e29b1a59c77 [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 Gregorio9ce4b622011-02-17 15:32:11 -050030 credentials = Storage('latitude.dat').get()
31 if credentials is None:
32 auth_discovery = build("latitude", "v1").auth_discovery()
33 flow = FlowThreeLegged(auth_discovery,
34 # You MUST have a consumer key and secret tied to a
35 # registered domain to use the latitude API.
36 #
37 # https://www.google.com/accounts/ManageDomains
38 consumer_key='REGISTERED DOMAIN NAME',
39 consumer_secret='KEY GIVEN DURING REGISTRATION',
40 user_agent='google-api-client-python-latitude/1.0',
41 domain='REGISTERED DOMAIN NAME',
42 scope='https://www.googleapis.com/auth/latitude',
43 xoauth_displayname='Google API Latitude Example',
44 location='current',
45 granularity='city'
46 )
47
48 credentials = run(flow, 'latitude.dat')
Joe Gregorio0802a172010-10-26 16:23:00 -040049
50 http = httplib2.Http()
51 http = credentials.authorize(http)
52
53 p = build("latitude", "v1", http=http)
54
55 body = {
56 "data": {
Joe Gregorioaf276d22010-12-09 14:26:58 -050057 "kind": "latitude#location",
58 "latitude": 37.420352,
59 "longitude": -122.083389,
60 "accuracy": 130,
61 "altitude": 35
Joe Gregorio0802a172010-10-26 16:23:00 -040062 }
63 }
64 print p.currentLocation().insert(body=body).execute()
65
66if __name__ == '__main__':
67 main()