我有一个与Firebase交互的AuthService类。然后在Signin.dart中,我想获得该用户,但是每次获得用户时遇到问题。我收到错误消息,表明Firebase无法发送用户。
错误:
发生异常。 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% 自动0;最大宽度:390像素;最小高度:180像素;填充:30像素0 15像素} *> 正文{background:url(// www.google.com/images/errors/robot.png)100%5px no-repeat; padding-right:205px} p {margin:11px 0 22px;溢出:隐藏} ins {颜色:#777;文本装饰:无} a img {border:0} @media屏幕和 (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屏幕和 (最低分辨率: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}} @仅媒体屏幕和 (-webkit-min-device-pixel-ratio:2){#logo {background:url(// www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 禁止重复; -webkit-background-size:100% 100%}}#logo {display:inline-block; height:54px; width:150px}
403。这是一个错误。
您的客户不 有权获取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 }
从这里 服务器。我们知道的就这些。 ], {}, 空值))
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")),
),
);
}
}
SignIn.dart
class ViewController: UIViewController {
@IBOutlet weak var sampImage: UIImageView!
override func viewDidLoad() {
super.viewDidLoad()
let tapGestureRecognizer = UITapGestureRecognizer(target: self, action: #selector(imageTapped(tapGestureRecognizer:)))
sampImage.isUserInteractionEnabled = true
sampImage.addGestureRecognizer(tapGestureRecognizer)
}
@objc func imageTapped(tapGestureRecognizer: UITapGestureRecognizer)
{
let tappedImage = tapGestureRecognizer.view as! UIImageView
let newImageView = UIImageView(image: tappedImage.image)
newImageView.frame = UIScreen.main.bounds
newImageView.backgroundColor = .black
newImageView.contentMode = .scaleAspectFit
newImageView.isUserInteractionEnabled = true
let tap = UITapGestureRecognizer(target: self, action: #selector(dismissFullscreenImage))
newImageView.addGestureRecognizer(tap)
self.view.addSubview(newImageView)
self.navigationController?.isNavigationBarHidden = true
self.tabBarController?.tabBar.isHidden = true
}
@objc func dismissFullscreenImage(_ sender: UITapGestureRecognizer) {
self.navigationController?.isNavigationBarHidden = false
self.tabBarController?.tabBar.isHidden = false
sender.view?.removeFromSuperview()
}
}
答案 0 :(得分:0)
在google-service.json
和build.gradle
文件中检查项目的ID必须相同。