Google 阅读器 API 身份验证
我正在尝试使用以下代码段在 google api 服务上进行身份验证:
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> converters =
new ArrayList<HttpMessageConverter<?>> restTemplate.getMessageConverters());
converters.add(new PropertiesHttpMessageConverter());
restTemplate.setMessageConverters(converters);
Properties result = preparePostTo(AUTHENTICATION_URL)
.using(restTemplate)
.expecting(Properties.class)
.withParam("accountType", "HOSTED_OR_GOOGLE")
.withParam("Email", email)
.withParam("Passwd", password)
.withParam("service", "reader")
.withParam("source", "google-like-filter")
.execute();
String token = (String) result.get("Auth");
现在我有类似以下的令牌:DQAAAI...kz6Ol8Kb56_afnFc(超过 100 个字符长度)并尝试获取网址:
URL url = new URL(LIKERS_URL + "?i=" + id);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.addRequestProperty("Authorization", "GoogleLogin Auth=" + token);
return url;
但是当我使用此网址获取内容时,我得到 401 客户端错误异常。会是什么?
根据这个问题 Google Reader Authentication Problem 一切都应该没问题。
我只需将网址粘贴到浏览器中即可获取内容。
I am trying to authenticate on google api service using this snippet:
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> converters =
new ArrayList<HttpMessageConverter<?>> restTemplate.getMessageConverters());
converters.add(new PropertiesHttpMessageConverter());
restTemplate.setMessageConverters(converters);
Properties result = preparePostTo(AUTHENTICATION_URL)
.using(restTemplate)
.expecting(Properties.class)
.withParam("accountType", "HOSTED_OR_GOOGLE")
.withParam("Email", email)
.withParam("Passwd", password)
.withParam("service", "reader")
.withParam("source", "google-like-filter")
.execute();
String token = (String) result.get("Auth");
Now I have token like: DQAAAI...kz6Ol8Kb56_afnFc (more than 100 chars length) and try to get url:
URL url = new URL(LIKERS_URL + "?i=" + id);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.addRequestProperty("Authorization", "GoogleLogin Auth=" + token);
return url;
But while I am getting content using this url I get 401 Client Error exception. What can it be?
According to this question Google Reader Authentication problem all should be fine.
I can get the content simply pasting the url into browser.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用 OAuth 进行 Google Reader 身份验证/授权。您只需使用 OAuth 库并向 Google 注册您的应用程序即可获取 OAuth 使用者密钥/秘密。
您可以使用 oauth.googlecode.com 或 抄写。
Try using OAuth for Google Reader authentication/authorization. You just need to use an OAuth library and register your app with Google to get OAuth consumer key/secret.
You can use oauth.googlecode.com or Scribe.
嘿,不知道这是否对您有帮助,或者您是否还关心,但我终于使用我编写的以下 ConsoleApp 代码进入了 Google Reader(请注意,这是 C#,但应该可以轻松转换为 Java)。
Hey, don't know if this will help you or if you even care anymore but I finally got into Google Reader with the following ConsoleApp code I whipped up (note that this is C# but should translate easily to Java).