Google OAuth を試しています。IBM WebSphere サーバーで実行する Web アプリケーションを開発しています。アプリケーションのフレームワークは SpringMVC です。
userinfo.profile を取得しようとしています。アクセス トークンの取得に成功しましたが、このトークンを使用してユーザー情報を取得する方法が見つかりませんでした。
ブラウザをこの URL にリダイレクトしてhttps://www.googleapis.com/oauth2/v2/userinfo?access_token="+access.getAccessToken();
いましたが、エラーが発生しました
{
"error": {
"errors": [
{
"domain": "global",
"reason": "authError",
"message": "Invalid Credentials",
"locationType": "header",
"location": "Authorization"
}
],
"code": 401,
"message": "Invalid Credentials"
}
}
このアクセス トークンを正しく使用していますか、それとも他の形式でリクエストを送信する必要がありますか?
私はこの方法でリクエストを送信しています:
GenericUrl shortenEndpoint = new GenericUrl("https://www.googleapis.com/oauth2/v2/userinfo");
HttpRequest request1 = rf.buildGetRequest(shortenEndpoint);
GoogleHeaders headers = new GoogleHeaders();
headers.setContentType("application/json; charset=UTF-8");
headers.setAuthorization("OAuth " + accessToken);
request1.setHeaders(headers);
HttpResponse shortUrl = request1.execute();
ブラウザでこの URL にアクセス トークンを指定した後
https://www.googleapis.com/oauth2/v1/tokeninfo?access_token=******
私は得た
{
"issued_to": "*****************",
"audience": "*****************",
"scope": "https://www.googleapis.com/auth/urlshortener",
"expires_in": 3515,
"access_type": "online"
}