I am integrating Huawei account kit. I want to know whether the AccessToken can be obtained through authAccount by using the following code:
private void silentSignIn() {
Task<AuthAccount> task = mAuthManager.silentSignIn();
task.addOnSuccessListener(new OnSuccessListener<AuthAccount>() {
@Override
public void onSuccess(AuthAccount authAccount) {
Log.i(TAG, "silentSignIn success");
Log.i(TAG, "touxiang: "+authAccount.getAvatarUriString());
}
});
task.addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(Exception e) {
//if Failed use getSignInIntent
if (e instanceof ApiException) {
ApiException apiException = (ApiException) e;
signIn();
}
}
});
}
Could anyone give any clue?
You can obtain a user-level AccessToken through silent sign-in.
First you need to check how the mAuthManager
object is initialized:
The mAuthManager
object can be initialized only when the following conditions are met:
//Call the default constructor of HuaweiIdAuthParamsHelper to set authorization parameters.
AccountAuthParams silentSignInParams = new AccountAuthParamsHelper(AccountAuthParams.DEFAULT_AUTH_REQUEST_PARAM)
.setAccessToken()
.createParams();
//Call the getService method of HuaweiIdAuthManager to initialize the HuaweiIdAuthService object.
AccountAuthService mAuthManager = AccountAuthManager.getService(getApplicationContext(), silentSignInParams);
//Call the HuaweiIdAuthService.silentSignIn method to send a silent sign-in request.
Task<AuthAccount> task = mAuthManager.silentSignIn();
The AccountAuthParams
object is required when the mAuthManager
object is initialized. When creating this object, you must set the .setAccessToken()
method to obtain the user-level access token using the authHuaweiId.getAccessToken()
method.
.setAccessToken()
method.