title: how to use Google Shortener API with Python
body: <p>I want to write an app to shorten url. This is my code:</p>
  
  <pre><code>import urllib, urllib2
  import json
  def goo_shorten_url(url):
      post_url = 'https://www.googleapis.com/urlshortener/v1/url'
      postdata = urllib.urlencode({'longUrl':url})
      headers = {'Content-Type':'application/json'}
      req = urllib2.Request(
          post_url,
          postdata,
          headers
          )
      ret = urllib2.urlopen(req).read()
      return json.loads(ret)['id']
  </code></pre>
  
  <p>when I run the code to get a tiny url, it throws an exception: <code>urllib2.HTTPError: HTTP Error 400: Bad Requests</code>.
  What is wrong with this code?</p>