未处理的异常:PlatformException(sign_in_failed,com.google.android.gms.common.api.ApiException:12500:,null)

时间:2019-07-16 06:50:25

标签: android firebase flutter firebase-authentication

请先阅读问题,然后再重复

我正在尝试在我的应用程序中使用google登录功能,但是此错误一直显示

我已完成以下操作:

  • 添加了支持电子邮件
  • 在Flutter控制台中激活了Google登录
  • 生成了sha1并将其签名为firebase
  • 添加了以下依赖性:
    • firebase_core:^ 0.4.0 + 6
    • firebase_auth:^ 0.11.1 + 8
    • google_sign_in:^ 4.0.4
    • rxdart:^ 0.22.0
    • cloud_firestore:^ 0.12.7
  • 已将gradle更新到5.1.1版(目前已发布)

我已经尝试过的方法:

这是应用程序的大脑

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();

1 个答案:

答案 0 :(得分:1)

我在这里找到了答案 https://github.com/flutter/flutter/issues/33393#issuecomment-510395178 您不必添加评论中列出的链接,只需使用任何内容更新图片即可使用

文档需要更新