gpt4 book ai didi

android - 静默登录成功后能否通过authAccount.getAccessToken()方法获取AccessToken

转载 作者:行者123 更新时间:2023-12-04 14:47:32 25 4
gpt4 key购买 nike

我正在集成华为帐户套件。我想知道是否可以使用以下代码通过authAccount获取AccessToken:

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();
}
}
});
}
任何人都可以提供任何线索吗?

最佳答案

您可以通过静默登录获得用户级别的AccessToken。

  • 首先你需要检查mAuthManager对象被初始化:
    enter image description here
  • mAuthManager只有满足以下条件时才能初始化对象:
  • //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();
    AccountAuthParams mAuthManager 时需要对象对象被初始化。创建此对象时,必须设置 .setAccessToken()使用 authHuaweiId.getAccessToken() 获取用户级访问 token 的方法方法。
  • 您可以检查您是否设置了.setAccessToken()方法。
  • 关于android - 静默登录成功后能否通过authAccount.getAccessToken()方法获取AccessToken,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69750262/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com