最近发现使用google api一直出现403错误,这是个认证错误。在网上查一下,发现是google api做了一些调整,增加了一些认证相关的参数
curl -d accountType=GOOGLE -d Email=xxx@gmail.com -d Passwd=xxx -d service=reader https://www.google.com/accounts/ClientLogin
SID=<SID value> # ignored
LSID=<LSID value> # ignored
Auth=<auth value>
在登录的时候,需要指定service,你所要登录使用的服务。如果参数正确,在返回的结果在内容中会多一个Auth项,这个项要在以后的请求中使用。
$ curl -H "Authorization:GoogleLogin auth=<auth value>" http://www.google.com/reader/api/0/user-info
{
"userId":"123",
"userName":"Name",
"userProfileId":"123",
"userEmail":"username@gmail.com",
"isBloggerUser":true,
"signupTimeSec":0,
"publicUserName":"username"
}
在调用API的时候,增加了Authorization请求头,头的内容是GoogleLogin auth=<auth value>,其中 auth value就是在登录时获取的。
如果你在使用googlebase-0.2.1库,请下载附件,并覆盖 \lib\google中的base.rb。