我尝试在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。我哪里出错了?在
您需要在POST中发送JSON,而不是URL编码的数据:
相关问题 更多 >
编程相关推荐