heltonbiker heltonbiker - 2 months ago 13x
HTTP Question

Using GET and POST with Authorization HTTP header in Python

I am trying to get the list of Maps created by me in Google Maps, and the Maps API says the following:

Retrieving a List of Maps

The Maps Data API provides a feed that lists the maps created by a particular user; this feed is known as a "metafeed". A typical Maps Data API metafeed is a GET request of the following form:

The default feed requests all maps associated with the authenticated user

GET http://maps.google.com/maps/feeds/maps/default/full
Authorization: GoogleLogin auth="authorization_token"

The standard metafeed requests all maps associated with the associated userID

GET http://maps.google.com/maps/feeds/maps/userID/full
Authorization: GoogleLogin auth="authorization_token"

Note that both GET requests require an Authorization HTTP header, passing an AuthSub or GoogleLogin token, depending on which authentication scheme you've implemented. (The GoogleLogin token corresponds to the ClientLogin authentication process.)

I have no idea how to create HTTP request with Authorization HTTP headers. I already have code to get the
, which is as follows:

# coding: utf-8

import urllib, re, getpass

# http://code.google.com/intl/pt-BR/apis/maps/documentation/mapsdata/developers_guide_protocol.html#ClientLogin

username = 'heltonbiker'
senha = getpass.getpass('Senha do usuário ' + username + ':')

dic = {
'accountType': 'GOOGLE',
'Email': (username + '@gmail.com'),
'Passwd': senha,
'service': 'local',
'source': 'helton-mapper-1'
url = 'https://www.google.com/accounts/ClientLogin?' + urllib.urlencode(dic)
output = urllib.urlopen(url).read()
authid = output.strip().split('\n')[-1].split('=')[-1]

I also took a look at
docs, but didn't understand much (I am not a professional programmer).

Any clue?


Using urllib2 will make everything easier:

import urllib2

request = urllib2.Request('http://maps.google.com/maps/feeds/maps/default/full')
request.add_header('Authorization', 'GoogleLogin auth=%s' % authorization_token)

BTW, isn't the Google Maps Data API deprecated? http://googlegeodevelopers.blogspot.com/2010/11/maps-data-api-deprecation-announcement.html