我正在尝试使用 flutter 应用程序登录 google,但出现此错误。 我已经获取并将 SHA-1 密钥放入 OAuth 和 Firebase,并在 app 目录下设置 google-services.json 文件。 但我仍然遇到同样的问题。
E/flutter (12401): [ERROR:flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 10: , null, null)
E/flutter (12401): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:607:7)
E/flutter (12401): #1 MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:156:18)
E/flutter (12401): <asynchronous suspension>
E/flutter (12401): #2 MethodChannel.invokeMapMethod (package:flutter/src/services/platform_channel.dart:356:43)
E/flutter (12401): <asynchronous suspension>
E/flutter (12401): #3 GoogleSignIn._callMethod (package:google_sign_in/google_sign_in.dart:235:30)
E/flutter (12401): <asynchronous suspension>
E/flutter (12401): #4 GoogleSignIn.signIn.isCanceled (package:google_sign_in/google_sign_in.dart)
E/flutter (12401): <asynchronous suspension>
E/flutter (12401):
我就是这样设置的。
而且我不知道哪个
必须位于该区域。clientId
clientId
必须位于该区域?
clientId
,因为我已经使用 google clientId
来使用 google django
进行网络登录
第1步: 将此依赖项添加到您的 pubsec 文件中
firebase: ^9.0.2
firebase_core: ^1.2.1
firebase_database: ^7.1.0
firebase_auth: ^1.2.0
font_awesome_flutter: ^9.0.0
google_sign_in: ^5.0.3
步骤:2 创建一个新的 dart 文件并粘贴此代码
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
class FirebaseService {
final FirebaseAuth _auth = FirebaseAuth.instance;
final GoogleSignIn _googleSignIn = GoogleSignIn();
Future<String?> signInwithGoogle() async {
try {
final GoogleSignInAccount? googleSignInAccount =
await _googleSignIn.signIn();
final GoogleSignInAuthentication googleSignInAuthentication =
await googleSignInAccount!.authentication;
final AuthCredential credential = GoogleAuthProvider.credential(
accessToken: googleSignInAuthentication.accessToken,
idToken: googleSignInAuthentication.idToken,
);
await _auth.signInWithCredential(credential);
} on FirebaseAuthException catch (e) {
print(e.message);
throw e;
}
}
Future<void> signOutFromGoogle() async{
await _googleSignIn.signOut();
await _auth.signOut();
}
}
第3步: 使用谷歌功能呼叫登录:
在 Firebase 中启用 Google 登录 将您的 SHA 1 密钥添加到 Firebase 项目