HarmonyOS 获取不到手机号

调用authentication模块的AuthorizationWithHuaweiIDRequest请求获取华为帐号的匿名手机号。获取不到手机号。

HarmonyOS  获取不到手机号-鸿蒙开发者社区

HarmonyOS
2024-11-01 10:09:44
1050浏览
收藏 0
回答 1
回答 1
按赞同
/
按时间
zxjiu

​确认下scope权限有没有申请,可参考:​https://developer.huawei.com/consumer/cn/doc/harmonyos-guides-V5/account-config-permissions-V5#section132012717318

保证华为帐号一键登录敏感权限以获取。

通过promise回调​。

getQuickLoginAnonymousPhone() { 
  // 创建授权请求,并设置参数。 
  let authRequest = new authentication.HuaweiIDProvider().createAuthorizationWithHuaweiIDRequest(); 
  // 获取手机号需要传如下scope,传参数之前需要先申请对应scope权限,才能返回对应数据。 
  authRequest.scopes = ['quickLoginAnonymousPhone']; 
  // 用于防跨站点请求伪造,非空字符串即可。 
  authRequest.state = util.generateRandomUUID(); 
  authRequest.forceAuthorization = false; 
  let controller = new authentication.AuthenticationController(getContext(this)); 
  try { 
    controller.executeRequest(authRequest).then((response: authentication.AuthorizationWithHuaweiIDResponse) => { 
      let anonymousPhone = response.data?.extraInfo?.quickLoginAnonymousPhone; 
      if (anonymousPhone) { 
        hilog.info(0x0000, 'testTag', 'authorization success'); 
        return; 
      } 
 
      hilog.info(0x0000, 'testTag', 'authorization success anonymousPhone is empty'); 
    }).catch((err: BusinessError) => { 
      hilog.error(0x0000, 'testTag', 'authorization fail: %{public}s', JSON.stringify(err)); 
    }) 
  } catch (err) { 
    hilog.error(0x0000, 'testTag', 'authorization fail: %{public}s', JSON.stringify(err)); 
  } 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
  • 21.
  • 22.
  • 23.
  • 24.
  • 25.

​建议在根页面通过Router跳转,进入页面以后再用navigation。

参考代码:​

let observer: UIObserver = this.getUIContext().getUIObserver(); 
observer.on('navDestinationUpdate', (info: observer.NavDestinationInfo) => { 
  let navDestinationInfo: observer.NavDestinationInfo | undefined = this.queryNavDestinationInfo(); 
  if (info?.navDestinationId !== navDestinationInfo?.navDestinationId) { 
    return; 
  } 
 
  if (info.state === uiObserver.NavDestinationState.ON_SHOWN) { 
    hilog.info(domainId, loginPanelTag, 'observerComponentState navDestinationInfo ON_SHOWN'); 
  } else if (info.state === uiObserver.NavDestinationState.ON_HIDDEN) { 
    hilog.info(domainId, loginPanelTag, 'observerComponentState navDestinationInfo ON_HIDDEN'); 
  } 
}); 
}
  • 1.
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
  • 7.
  • 8.
  • 9.
  • 10.
  • 11.
  • 12.
  • 13.
  • 14.
分享
微博
QQ
微信
回复
2024-11-01 16:29:11


相关问题
华为账号登录获取不到手机号
1425浏览 • 1回复 待解决
HarmonyOS 如何获取手机号
715浏览 • 1回复 待解决
如何获取华为手机号
345浏览 • 0回复 待解决
HarmonyOS 手机号快速验证
903浏览 • 1回复 待解决
鸿蒙OS如何获取当前的手机号
26063浏览 • 1回复 待解决
HarmonyOS 如何一键获取本机手机号
864浏览 • 1回复 待解决
PersistentStorage实现手机号登录匹配
1644浏览 • 1回复 待解决
快速验证手机号Button的实现
1310浏览 • 1回复 待解决
实时验证手机号Button的实现
1134浏览 • 1回复 待解决
HarmonyOS 手机号一键登录功能
715浏览 • 1回复 待解决
HarmonyOS 输入框关于手机号空格问题
1016浏览 • 1回复 待解决
验证手机号是否已被注册/绑定功能?
4840浏览 • 1回复 待解决
HarmonyOS 如何实现手机号344格式实现?
1246浏览 • 1回复 待解决
HarmonyOS不到手机内部的数据文件
804浏览 • 1回复 待解决