このスニペットを使用して 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 url = new URL(LIKERS_URL + "?i=" + id);
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.addRequestProperty("Authorization", "GoogleLogin Auth=" + token);
return url;
しかし、この URL を使用してコンテンツを取得しているときに、401 クライアント エラー例外が発生します。それは何でしょうか?
この質問Google リーダー認証の問題によると、すべて問題ありません。
URLをブラウザに貼り付けるだけでコンテンツを取得できます。