![](/img/trans.png)
[英]Flutter Google Sign and Phone Auth error after publishing the app com.google.android.gms.common.api.b 10
[英]PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null) Getting this error While Sign in with Google Play
我想使用 Google Play 服務登錄,但出現此錯誤...我嘗試了所有可能的解決方案,例如添加 SHA-1、生成客戶端 ID、發布同意屏幕,但它仍然出現此異常這是我的代碼片段
Future<AuthCredential?> getGoogleCredential() async {
print('Inside getGoogleCredential');
final GoogleSignIn googleSignIn = GoogleSignIn(
signInOption: SignInOption.games,
scopes: [GamesApi.gamesScope],
clientId: 'client id',
hostedDomain: 'my hosted domain',
);
// print('google Sign in is ${googleSignIn.clientId}');
print('google Sign in is ${googleSignIn.currentUser}');
final GoogleSignInAccount? googleUser =
await googleSignIn.signIn().catchError((error) {
print('Failed to sign in with Google Play Games: $error');
});
print('google User is ${googleUser}');
if (googleUser == null) {
print('Failed to sign in with Google Play Games.');
return null;
}
final GoogleSignInAuthentication googleAuth =
await googleUser.authentication;
final credential = GoogleAuthProvider.credential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
return credential;
}
Future signIn() async {
final AuthCredential? googleCredential = await getGoogleCredential();
if (googleCredential != null) {
await FirebaseAuth.instance.signInWithCredential(googleCredential);
} else {
print('Trying signInAnonymously');
await FirebaseAuth.instance.signInAnonymously();
}
}
基本上錯誤是ApiException: 10 。 要解決這個問題,您需要在谷歌雲控制台上使用SHA1注冊您的應用程序。
轉到https://console.cloud.google.com/
單擊憑據 > 創建憑據 >OAuth 客戶端 ID
選擇您希望應用程序在其中運行的平台。
填寫您的應用程序的包名稱。
為了填寫 SHA1 值,打開命令行並 cd 到主項目文件夾中的 android 文件夾,然后鍵入命令./gradlew signingReport然后按 Enter。 完成一些計算后,您將看到擴展 mac 地址格式的 SHA1 值。
如果您在終端中遇到錯誤,請安裝您的 gradle 版本支持的 java jdk (截至本答案時,支持 java jdk 版本 14)並將其路徑(包括 windows 環境變量中的 bin 文件夾)設置為新路徑
如果您忘記將 Google Play SHA1 控制台添加到 firebase 應用設置,也會發生這種情況
怎么做:
go 到 Google Play 控制台 -> 您的應用程序 -> 應用程序完整性 -> 應用程序簽名 -> 應用程序簽名密鑰證書 -> 復制 SHA-1 和 SHA-256
go 到 firebase 項目設置並添加以上 SHA-1 和 SHA-256
理想情況下,您應該在 firebase 設置中擁有 6 個證書。
3 SHA-1 -->(開發/發布/播放控制台)
3 SHA-256 -->(開發/發布/播放控制台)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.