coding UTF-8 import json import logging from grab import Grab logging

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
# -*- coding: UTF-8 -*-
import json
import logging
from grab import Grab
logging.basicConfig(level=logging.DEBUG)
APIKEY = 'AIzaSyAlmUacFRrF0R4w'
g = Grab()
g.setup(headers={'Content-Type': 'application/json'})
g.setup(post="{'longUrl': 'http://ya.ru'}")
g.go('https://www.googleapis.com/urlshortener/v1/url?key=%s' % APIKEY)
link = json.loads(g.response.body)
print link['id']