我能够通过GoogleSignInAccount.getIdToken()
收到Google ID令牌,因此我对如何处理它几乎没有疑问
答案 0 :(得分:0)
1.为了不使服务器过载,我们决定生成具有相同到期时间(1小时)的内部(短)访问令牌
2.再次调用登录功能可以实现提示刷新:
private void loginGoogle(){
//context is Activity
GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(context.getString(R.string.default_web_client_id)).requestEmail()
.build();
if (googleApiClient!=null) {
googleApiClient.stopAutoManage((FragmentActivity) context);
googleApiClient.disconnect();
}
googleApiClient = new GoogleApiClient.Builder(context)
.enableAutoManage((FragmentActivity) context, new GoogleApiClient.OnConnectionFailedListener() {
@Override
public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
Log.d("auth", "connection failed");
}
})
.addApi(Auth.GOOGLE_SIGN_IN_API, gso)
.build();
//
OptionalPendingResult<GoogleSignInResult> opr =
Auth.GoogleSignInApi.silentSignIn(googleApiClient);
if (opr.isDone()) {
GoogleSignInResult r = opr.get();
Log.d("auth", "google silent signin sync");
fillGoogleProfile(r.getSignInAccount());
} else {
opr.setResultCallback(new ResultCallback<GoogleSignInResult>() {
@Override
public void onResult(@NonNull GoogleSignInResult result) {
Log.d("auth", "google silent signin async");
if (result.getSignInAccount()==null) {
Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(googleApiClient);
//catch result in the onActivityResult
context.startActivityForResult(signInIntent, RC_SIGN_IN);
return;
}
fillGoogleProfile(result.getSignInAccount());
}
});
}
}
3.还没有找到答案