身份验证GReader编辑API遇到问题.我可以进行HTTPS(https://www.google.com/accounts/ClientLogin)进行身份验证,并且google返回三个令牌(SID,LSID,AUTH),但没有HSID.
当我尝试使用POST数据T = djj72HsnLS8293& quickadd = blog.martindoms.com / feed /添加新的Feed http://www.google.com/reader/api/0/subscription/quickadd?ck=1290452912454&client=scroll时,在Cookie中没有HSID时,响应状态代码为401.在Cookie中使用SID和HSID时,一切正常.
什么是HSID字符串,在哪里可以找到?
感谢您的回答.
我的代码:
public void addNewFeed() throws IOException {
HttpPost requestPost = new HttpPost("http://www.google.com/reader/api/0/subscription/quickadd?ck=1290452912454&client=scroll");
getSid();
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
DefaultHttpClient client = new DefaultHttpClient();
requestPost.addHeader("Cookie", "SID=" + _sid + "; HSID=" + _hsid);
try {
nameValuePairs.add(new BasicNameValuePair("T", _token));
nameValuePairs.add(new BasicNameValuePair("quickadd", "blog.martindoms.com/feed/"));
requestPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = client.execute(requestPost);
InputStream in = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
StringBuilder str = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
str.append(line + "\n");
}
System.out.println(str.toString());
in.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
解决方法:
看起来您可能正在使用旧信息作为参考. Google现已切换为使用身份验证.
您需要将getSid()替换为getAuth()函数.
然后这条线
requestPost.addHeader("Cookie", "SID=" + _sid + "; HSID=" + _hsid);
现在应该是这个
requestPost.addHeader("Authorization", "GoogleLogin auth=" + _auth);