[英]Unhandled Exception: PlatformException(sign_in_failed, com.google.android.gms.common.api.ApiException: 12500: , null)
Please read the question before sitting it to duplicate请在坐下来复制之前阅读问题
I'm trying to make google sign in feature in my app but this error keeps showing up我正在尝试在我的应用中使用谷歌登录功能,但此错误不断出现
I've done the following:我做了以下事情:
what I already tried:我已经尝试过的:
here is the brains of the app这是应用程序的大脑
import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:firebase_auth/firebase_auth.dart';
import 'package:google_sign_in/google_sign_in.dart';
import 'package:rxdart/rxdart.dart';
class AuthService {
final GoogleSignIn _googleSignIn = GoogleSignIn();
final FirebaseAuth _auth = FirebaseAuth.instance;
final Firestore _db = Firestore.instance;
Observable<FirebaseUser> user;
Observable<Map<String, dynamic>> profile;
PublishSubject loading = PublishSubject();
AuthService() {
user = Observable(_auth.onAuthStateChanged);
profile = user.switchMap((FirebaseUser u) {
if (u != null) {
return _db
.collection('users')
.document(u.uid)
.snapshots()
.map((snap) => snap.data);
} else {
return Observable.just({});
}
});
}
Future<FirebaseUser> googleSignIn() async {
loading.add(true);
GoogleSignInAccount googleUser = await _googleSignIn.signIn();
GoogleSignInAuthentication googleAuth = await googleUser.authentication;
final AuthCredential credential = GoogleAuthProvider.getCredential(
accessToken: googleAuth.accessToken,
idToken: googleAuth.idToken,
);
final FirebaseUser user = await _auth.signInWithCredential(credential);
print("signed in " + user.displayName);
updateUserData(user);
loading.add(false);
print("signed in " + user.displayName);
return user;
}
void updateUserData(FirebaseUser user) async {
DocumentReference ref = _db.collection('users').document(user.uid);
return ref.setData({
'uid': user.uid,
'email': user.email,
'photoURL': user.photoUrl,
'displayName': user.displayName,
'lastSeen': DateTime.now()
}, merge: true);
}
void signOut() {
_auth.signOut();
}
}
final AuthService authService = AuthService();
I found the answer here https://github.com/flutter/flutter/issues/33393#issuecomment-510395178 you don't have to add the links listed in the comment, just update the picture with anything and it will work我在这里找到了答案https://github.com/flutter/flutter/issues/33393#issuecomment-510395178您不必添加评论中列出的链接,只需用任何内容更新图片即可
the docs needs to be updated文档需要更新
For me adding scopes and hostedDomain in GoogleSignIn method works.对我来说,在 GoogleSignIn 方法中添加范围和托管域是可行的。
final GoogleSignInAccount? googleUser = await GoogleSignIn(
scopes: ['email', 'profile'],
hostedDomain: '',
).signIn();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.