現在、アンドロイドアプリはGoogleAuthUtilを使用してユーザーにログインし、access_token
を取得します(下のコードスニペットではGoogleApiClientを作成し、GoogleAuthUtilを使用してトークンを取得します)。私はその後、バックエンドGoogleログイン新しいGoogleSignInOptionsを使用してアクセストークンを取得
私は今、新しいGoogle SIGNINに移動しようとしているに送信
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Plus.API)
.addScope(new Scope("profile"))
.build();
...
...
String accessToken = GoogleAuthUtil.getToken(GoogleLoginActivity.this,
Plus.AccountApi.getAccountName(mGoogleApiClient),
"oauth2:profile email");
- https://developers.google.com/identity/sign-in/android/sign-in
をし、そのようなGoogleApiClientの作成を変更し、
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.requestIdToken("<web client id>")
.build();
mGoogleApiClient = new GoogleApiClient.Builder(this)
.enableAutoManage(this, this)
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
ログインの使用を行います。
と(上記のリンクの例と同様)活動の結果使用上の10、
OptionalPendingResult<GoogleSignInResult> opr = Auth.GoogleSignInApi.silentSignIn(mGoogleApiClient);
if (opr.isDone()) {
// If the user's cached credentials are valid, the OptionalPendingResult will be "done"
// and the GoogleSignInResult will be available instantly.
Log.d(TAG, "Got cached sign-in");
handleSignInResult(opr.get());
} else {
// If the user has not previously signed in on this device or the sign-in has expired,
// this asynchronous branch will attempt to sign in the user silently. Cross-device
// single sign-on will occur in this branch.
showProgress();
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(GoogleSignInResult googleSignInResult) {
hideProgress();
handleSignInResult(googleSignInResult);
}
});
}
が、今、handleSingInResult(GoogleSignInResult result)
に私が唯一 result.getSignInAccount().getIdToken();
バックid token
を得ることができるようですが誰もい(以前のように)これからアクセストークンを取得することが可能かどうかを知っています。どんな助けもありがたい。あなたに署名した後
私はここで同じ問題を抱えていますが、あなたはこの問題を回避することができましたか? –
本当にありません。私がこれを使い始める前に、バックエンドでIDトークン処理を実装しなければなりませんでした。 – Bootstrapper
私はAndroidのアカウントピッカーを使用してアカウント名を取得し、GoogleAuthUtil.getToken(コンテキスト、accoutName、スコープ)を使用してトークン自体を取得しましたが、それは魅力的であり、最初のものほど簡単でした。 –