首页 > 解决方案 > Firebase 不返回用户

问题描述

我有一个与 Firebase 交互的 AuthService 类。然后在 Signin.dart 中,我想获取该用户,但每次获取用户时遇到问题。我收到错误消息,显示 Firebase can't send the user 。

错误:

发生异常。PlatformException(PlatformException(firebase_auth,com.google.firebase.FirebaseException:发生内部错误。[错误 403(禁止)!!1

*{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0; max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding -right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body {background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png ) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp. png) 不重复 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media 仅屏幕和 (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google. com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px}

403.这是一个错误。

您的客户端无权 /identitytoolkit/v3/relyingparty/signupNewUser从此服务器获取 URL。我们知道的就这些。], {}, 无效的))

import 'package:firebase_auth/firebase_auth.dart';

class AuthService {
  final FirebaseAuth _auth = FirebaseAuth.instance;

  // sign in anon
  Future signInAnon() async {
    try {
      UserCredential userCredential = await _auth.signInAnonymously();
      User user = userCredential.user;
      return user;
    } catch (e) {
      print(e.toString());
      return null;
    }
  }

  // sign in with email and password

  // register with email and password

  // sign out

}

登录.dart

import 'package:auth_flutter_coffe/Services/Auth.dart';
import 'package:flutter/material.dart';

class SignIn extends StatefulWidget {
  @override
  _SignInState createState() => _SignInState();
}

class _SignInState extends State<SignIn> {
  final AuthService _auth = AuthService();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.brown[700],
      appBar: AppBar(
        title: Text("SignIn"),
        centerTitle: true,
        backgroundColor: Colors.brown[900],
      ),
      body: Container(
        padding: EdgeInsets.symmetric(horizontal: 50.0, vertical: 50.0),
        child: RaisedButton.icon(
            onPressed: () async {
              dynamic result = await _auth.signInAnon();
              if (result == null) {
                print("You Have to be SignIn");
              } else {
                print("SignIn");
                print(result);
              }
            },
            icon: Icon(Icons.transit_enterexit),
            label: Text("SignIn")),
      ),
    );
  }
}

标签: firebaseflutterdartfirebase-authentication

解决方案


检查您的项目的 idgoogle-service.jsonbuild.gradle文件必须相同。


推荐阅读