googleurl shortenerAPI与python返回

2024-09-29 21:30:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我尝试在python代码中调用Google URL Shortener API:

def shorternUrl():
        API_KEY = "AIzaSyCvhcU63u5OTnUsdYaCFtDkcutNm6lIEpw"
        apiUrl = 'https://www.googleapis.com/urlshortener/v1/url'
        longUrl = "http://www.cnn.com"
        headers = {"Content-type": "application/json"}
        data = {"longUrl": longUrl}
        h = httplib2.Http('.cache')
        try:
            headers, response = h.request(apiUrl, "POST", urllib.urlencode(data), headers)
            print response

        except Exception, e:
            print "unexpected error %s" % e

但我一直收到这样的错误:

^{pr2}$

我没有使用googleapi for Python。我哪里出错了?在


Tags: 代码comapiurldataresponsedefwww

热门问题