Iグーグルhttps://developers.google.com/identity/sign-in/web/server-side-flowから次の例を使用し、これまで私は、次の手順を達成することができました:取得TokenResponseException:401権限
- ユーザーは、クライアント側での認証(ブラウザ)
- コードが戻されるのとサーバーのデータベースに保存されました
- 認証コードを要求するときTokenResponseException:401 Unauthorized。私は次のようにチェック
:
- APIがhttps://developers.google.com/oauthplayground上
- を有効になっている私は、同じクライアントIDとクライアントシークレットとのアクセスをテストし、それが
- の作品は、ほとんどすべてだったSOクエリを読みますこの問題に関連していますが、本当に助けられた人はいませんでした。
- すべてのユーザーのアクセス許可を取り消し、新しいコードを取得するように依頼しました。以下は
は、私が使用していたコードです:私はsetRedirectUri使用didntの場合は、
public void getUserAuthTokens(String authCode){
try {
GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(
JacksonFactory.getDefaultInstance(),new FileReader(new ClassPathResource("static\\client_secret.json").getFile()));
List<String> scopes = new ArrayList<>();
scopes.add("https://www.googleapis.com/auth/gmail.readonly");
//String scopes[]={"https://www.googleapis.com/auth/gmail.readonly"};
Collection<String> SCOPES
= Collections.unmodifiableCollection(
Arrays.asList(
new String[]{
GmailScopes.GMAIL_READONLY
}));
GoogleTokenResponse tokenResponse = new GoogleAuthorizationCodeTokenRequest(new NetHttpTransport(),JacksonFactory.getDefaultInstance(),
"https://www.googleapis.com/oauth2/v4/token",
clientSecrets.getDetails().getClientId(),
clientSecrets.getDetails().getClientSecret(),
authCode).setRedirectUri(clientSecrets.getDetails().getRedirectUris().get(0)).setScopes(SCOPES).execute();
String accessToken = tokenResponse.getAccessToken();
System.out.print("Token is: "+accessToken);
}catch (IOException x){
x.printStackTrace();
}
}
サイドノートとして(。。)(clientSecrets.getDetailsをgetRedirectUris()(0)を取得)それから私は得ました私は、GoogleのAPIが返すStandard Error Responses、不正なエラーコード401から基づい
私は本当にここでいくつかの援助が必要です私はこれをひっくり返すことができません – user2145673