简体   繁体   English

Firebase 实时数据库连接终止:不同区域

[英]Firebase Realtime Database connection killed: Different Region

I am trying to build a simple login user authentication Android application that uses Firebases Realtime Database but I am getting the error:我正在尝试构建一个使用 Firebases 实时数据库的简单登录用户身份验证 Android 应用程序,但出现错误:

[Firebase Database connection was forcefully killed by the server. [Firebase 数据库连接被服务器强行终止。 Will not attempt to reconnect.不会尝试重新连接。 Reason: The database lives in a different region.原因:数据库位于不同的区域。 Please change your database URL to https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app]请将您的数据库 URL 更改为 https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app]

I am currently using the Singapore(asia-southeast1) server since I live in the Philippines.我住在菲律宾,目前正在使用新加坡(asia-southeast1)服务器。 Is this wrong?这是错误的吗? or Should I be using the US one?或者我应该使用美国的吗? How do I change my Database URL?如何更改我的数据库 URL?

It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created.您使用的google-services.json文件似乎不包含实时数据库 URL,可能是因为您在创建数据库之前下载了它。 In such cases the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.在这种情况下,SDK 假定数据库位于美国(原始区域),并且您会收到一个错误,指出存在不匹配。

There are two possible solutions:有两种可能的解决方案:

  1. Download an updated google-services.json from the Firebase console, and add that to your Android app.从 Firebase 控制台下载更新的google-services.json ,并将其添加到您的 Android 应用中。
  2. Specify the database URL in your code instead, like this: FirebaseDatabase.getInstance("https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app")...在代码中指定数据库 URL,如下所示: FirebaseDatabase.getInstance("https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app")...

Both have the same result, so pick whichever one seems easiest to you.两者都有相同的结果,因此请选择您认为最简单的一个。

将 URL 传递到getInstance方法应该可以解决这个问题:

DatabaseReference database = FirebaseDatabase.getInstance(“https://vax-in-60807-default-rtdb.asia-southeast1.firebasedatabase.app”).getReference();

It cat still not work after the accepted answer (as in my case).在接受答案后,它仍然无法正常工作(就像我的情况一样)。 If so, try:如果是这样,请尝试:

  • Clean Project清洁工程
  • Rebuild Project重建项目
  • Invalidate Caches & Restarte使缓存无效并重新启动

and run it again.并再次运行它。

If you are a New Flutter User who followed the new firebase doc , run this command in the terminal.如果您是关注新firebase 文档的新 Flutter 用户,请在终端中运行此命令。 It will automatically update the firebase_options.dart file.它将自动更新 firebase_options.dart 文件。

flutterfire configure

I faced the same problem and that's because when you set up the app, the google-service.json doesn't contain the firebase_url.我遇到了同样的问题,那是因为当您设置应用程序时,google-service.json 不包含 firebase_url。

These problems faced you when configuring your set up manually, You can fix all that problems by using flutterfire , it will help you a lot and set up your app in a few steps.这些问题在您手动配置设置时会遇到,您可以使用flutterfire解决所有这些问题,它将为您提供很多帮助,并通过几个步骤设置您的应用程序。 see docsfirebase请参阅文档firebase

It looks like the google-services.json file that you use doesn't contain the Realtime Database URL, probably because you downloaded it before the database was created.看起来您使用的 google-services.json 文件不包含实时数据库 URL,可能是因为您在创建数据库之前下载了它。 In such cases, the SDK assumes that the database is in the US (the original region), and you get an error that there's a mismatch.在这种情况下,SDK 假定数据库位于美国(原始区域),并且您会收到错误信息,指出不匹配。

You can fix it either way.您可以通过任何一种方式修复它。

  1. After configuring the database service setup you have to download the new "GoogleService-Info.plist" file and replace the previous one.配置数据库服务设置后,您必须下载新的“GoogleService-Info.plist”文件并替换之前的文件。

or要么

  1. You can manually set the key in your "GoogleService-Info.plist" file您可以在“GoogleService-Info.plist”文件中手动设置密钥

<key>DATABASE_URL</key> <string>https://<app-instance-default-rtdb>.asia-southeast1.firebasedatabase.app</string> ' <key>DATABASE_URL</key> <string>https://<app-instance-default-rtdb>.asia-southeast1.firebasedatabase.app</string> '

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM