[英]Flutter Firebase Auth / Google_sign_in fail to login with statuscode=CANCELED
這是我的pubspec.yaml。 我正在使用Flutter:
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
shared_preferences: ^0.4.2
json_serializable: ^1.2.1
camera: ^0.2.3
path_provider: ^0.4.1
simple_permissions: ^0.1.6
share: ^0.5.3
#Google Sign_In
firebase_auth: ^0.5.20
google_sign_in: ^3.0.5
我無法使用Google登錄方法進行身份驗證。 該窗口正常顯示,並且在我的應用拋出錯誤后:
PlatformException(sign_in_failed, Status{statusCode=CANCELED, resolution=null}, null)
尚未在線找到任何解決方案,有人可以幫我嗎?
以下是我的_signIn()
方法
Future<FirebaseUser> _signIn() async {
GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
GoogleSignInAuthentication gSA = await googleSignInAccount.authentication;
FirebaseUser user = await auth.signInWithGoogle(
idToken: gSA.idToken, accessToken: gSA.accessToken);
print("User Name : ${user.displayName}");
return user;
}
我致電GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
后,我的代碼崩潰了GoogleSignInAccount googleSignInAccount = await googleSignIn.signIn();
所以我的猜測是,我的設置錯誤。
這就是我所謂的_signIn()
MaterialButton(
child: Text("Google Sign-In"),
onPressed: (){
_signIn()
.then((FirebaseUser user) => print(user))
.catchError((e) => print(e));
},
),
我已經在線上刪除了Google開發人員控制台上的Firebase-Project並創建了一個新的。 我也嘗試了匿名登錄->效果很好
任何幫助表示贊賞
好的,因此我設法在發布模式下使用APK來解決此問題!
您要做的是:
在發布模式下構建您的應用,然后將SHA1或SHA256添加到您的Firebase項目中。
如果您不知道如何准備發布應用,則可以快速進行操作。
我只是遇到了同樣的問題。 這就是我解決的方法。
1)獲取您的SHA1證書密鑰。 (請參閱https://developers.google.com/android/guides/client-auth )
2)將SHA1鍵放在Firebase控制台中
3)重建您的Flutter應用,然后重試。 它應該現在正在工作。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.