Flutter中Apple登录无法稳定获取用户姓名问题求助
Apple登录无法稳定获取用户全名,仅重新登录Apple账号时返回
我在实现Apple登录功能时遇到一个问题:无法从Apple凭证中稳定获取用户全名,目前只能稳定拿到邮箱信息。只有当用户在设备上重新登录Apple账号后,才能获取到全名;如果设备上的Apple账号保持登录状态,姓名字段就会返回null。
这是我的Apple登录功能代码:
signInWithApple(Ref ref) async { try { final FirebaseAuth auth = FirebaseAuth.instance; final AuthorizationCredentialAppleID appleCredential = await SignInWithApple.getAppleIDCredential( scopes: [ AppleIDAuthorizationScopes.email, AppleIDAuthorizationScopes.fullName ], webAuthenticationOptions: WebAuthenticationOptions( clientId: 'clientId', redirectUri: Uri.parse('uri'), ), ); final OAuthProvider oAuthProvider = OAuthProvider('apple.com'); final credential = oAuthProvider.credential( idToken: appleCredential.identityToken, accessToken: appleCredential.authorizationCode); final User? user = (await auth.signInWithCredential(credential)).user; if (user?.email != null) { ref .read(authProvider.notifier) .setAppleEmailToRegistration(user!.email!); final Either<CleanFailure, EmailLoginSecondStepResponse> data = await api.post( fromData: (json) => EmailLoginSecondStepResponse.fromMap(json), endPoint: APIRoute.socialLogin, body: {"email": user.email}, withToken: false, ); return data; } else { return left( CleanFailure.withData( tag: "Apple sign-in error", url: "apple.com", method: "POST", statusCode: 000, header: const {}, body: const {}, error: const CleanError( message: "Apple sign-in error", ), ), ); } } catch (e) { Logger.e("Apple sign in error: $e"); return left( CleanFailure.withData( tag: "Apple sign-in error", url: "apple.com", method: "POST", statusCode: 000, header: const {}, body: const {}, error: CleanError( message: e.toString(), ), ), ); } }
恳请各位帮忙解决这个问题!
内容的提问来源于stack exchange,提问作者Nazmul Hasan
相关产品推荐
相关产品推荐

