Skip to content

Instantly share code, notes, and snippets.

@comfuture
Created January 2, 2011 11:50
Show Gist options
  • Save comfuture/762467 to your computer and use it in GitHub Desktop.
Save comfuture/762467 to your computer and use it in GitHub Desktop.
import urllib
import urlparse
import oauth2 as oauth
import time
consumer_key = 'YOUR_CONSUMER_KEY'
consumer_secret = 'YOUR_CONSUMER_SECRET'
class Latitude(oauth.Client):
LATITUDE_KEY = 'YOUR_LATITUDE_KEY'
REQUEST_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetRequestToken'
ACCESS_TOKEN_URL = 'https://www.google.com/accounts/OAuthGetAccessToken'
AUTHORIZE_URL = 'https://www.google.com/latitude/apps/OAuthAuthorizeToken'
API_BASE = 'https://www.googleapis.com/latitude/v1/'
def __init__(self, consumer_key, consumer_secret):
self.consumer = oauth.Consumer(consumer_key, consumer_secret)
oauth.Client.__init__(self, self.consumer)
params = {
'oauth_version': '1.0',
'oauth_nonce': oauth.generate_nonce(),
'oauth_timestamp': int(time.time()),
'scope': 'https://www.googleapis.com/auth/latitude'
}
resp, content = self.request('%s?%s' % (self.REQUEST_TOKEN_URL, urllib.urlencode(params)), 'GET')
if resp['status'] != '200':
raise Exception('Invalid response %s' % resp['status'])
request_token = dict(urlparse.parse_qsl(content))
print 'Access this url:'
print '%s?domain=maroo.info&location=all&granularity=best&oauth_token=%s' % (self.AUTHORIZE_URL, request_token['oauth_token'])
raw_input('Then press enter: ')
self.token = oauth.Token(request_token['oauth_token'], request_token['oauth_token_secret'])
self.request(self.ACCESS_TOKEN_URL, 'POST')
access_token = dict(urlparse.parse_qsl(content))
print access_token
def get_current_location(self):
resp, content = self.request('%s%s?key=%s' % (self.API_BASE, 'currentLocation', self.LATITUDE_KEY,), 'GET')
print resp, content
if __name__ == '__main__':
lat = Latitude(consumer_key, consumer_secret)
lat.get_current_location()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment