- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在我的 Android 项目中使用 Firebase(版本 10.0.0)并遇到以下 Firebase 数据库问题:
先决条件:用户使用 Google 帐户通过 Firebase Auth 登录(FirebaseAuth.getInstance().getCurrentUser() 返回非空值)。
FirebaseDatabase.getInstance()
.getReference()
.child(NODE_USERS).child(user.getUid()).child(NODE_DICTIONARY_VERSION)
.addListenerForSingleValueEvent(...);
W/PersistentConnection: pc_0 - Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key. You can re-download google-services.json from https://console.firebase.google.com/
After that all other calls to Firebase Database (read, write, remove, etc) also don't work.
To fix this I tried to
FirebaseAuth.getInstance().getCurrentUser().reauthenticate(credential).addOnCompleteListener(...);
FirebaseDatabase.getInstance().goOffline();FirebaseDatabase.getInstance().goOnline();
As a result, the problem with Firebase Database appears not so often and at least after a day has passed. Also the problem is disappeared for a some time if to restart the whole application (without these fixes the problem reproduces every time, only re-login helps).
Anyway, the problem still exists and application restart is a very bad solution :)
Any idea how to fix this problem? Or maybe I'm doing something wrong?
The full Firebase log:
12-19 13:03:40.544 D/FirebaseAuth: Notifying listeners about user ( HbY7R8FPR6QwgstQd3wmypI2nwJ2 ).
12-19 13:03:40.546 D/FirebaseApp: Notifying auth state listeners.
12-19 13:03:40.546 D/FirebaseApp: Notified 1 auth state listeners.
12-19 13:03:40.546 D/RepoOperation: Auth token changed, triggering auth token refresh
12-19 13:03:40.602 D/FirebaseAuth: Notifying listeners about user ( HbY7R8FPR6QwgstQd3wmypI2nwJ2 ).
12-19 13:03:40.613 D/FirebaseApp: Notifying auth state listeners.
12-19 13:03:40.613 D/FirebaseApp: Notified 1 auth state listeners.
12-19 13:03:40.613 D/RepoOperation: Auth token changed, triggering auth token refresh
12-19 13:03:43.832 V/FA: Session started, time: 176462962
12-19 13:03:43.853 I/FA: Tag Manager is not found and thus will not be used
12-19 13:03:43.858 D/FA: Logging event (FE): _s, Bundle[{_o=auto, _sc=MainActivity, _si=3824046701607023337}]
12-19 13:03:43.885 V/FA: Using measurement service
12-19 13:03:43.885 V/FA: Connecting to remote service
12-19 13:03:43.909 D/FA: Connected to remote service
12-19 13:03:43.910 V/FA: Processing queued up service tasks: 1
12-19 13:03:44.139 W/PersistentConnection: pc_0 - Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key. You can re-download google-services.json from https://console.firebase.google.com/.
12-19 13:03:45.985 W/PersistentConnection: pc_0 - Provided authentication credentials are invalid. This usually indicates your FirebaseApp instance was not initialized correctly. Make sure your google-services.json file has the correct firebase_url and api_key. You can re-download google-services.json from https://console.firebase.google.com/.
12-19 13:03:48.945 V/FA: Inactivity, disconnecting from the service
附言看起来问题只出现在我的 Nexus 5 (Android 6.0.1) 上。 Sony Xperia V (Android 4.3) 没有这个问题。
附言我还尝试构建调试和发布 apk,并向谷歌云控制台中的所有自动生成的服务帐户添加“编辑器”角色——这也无济于事。
最佳答案
感谢 Firebase 支持工程师,我终于找到了解决问题的方法! :)
诀窍是等待从 FirebaseAuth.AuthStateListener 获取 FirebaseAuth(而不是直接从 FirebaseAuth.getInstance() 获取)在访问 Firebase 数据库之前在应用程序启动时:看起来 Firebase 需要一些时间来初始化/更新用户身份验证。
所以,下面的代码不能正常工作:
// Main Activity
protected void onCreate(...) {
if (FirebaseAuth.getInstance().getCurrentUser() != null) {
// accessing Firebase Database
}
}
它必须是这样的:
protected void onCreate(...) {
//...
authStateListener = new FirebaseAuth.AuthStateListener() {
@Override
public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user != null) {
// accessing Firebase Database
}
}
};
FirebaseAuth.getInstance().addAuthStateListener(authStateListener);
}
关于android - 适用于 Android 的 Firebase - W/PersistentConnection : pc_0 - Provided authentication credentials are invalid,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41221491/
正在复制的问题是,当sew呈现登录页面时,然后我们继续执行身份验证,现在将我们重定向到网站的仪表板,此时我们继续关闭会话,并且在之前的交互中生成的这些cookie没有被删除。这个问题是重复性的,并且一
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我是 Flutter 的新手,目前正在研究 DI。 我正在使用 flutter_bloc 和 provider 包。 flutter_bloc 附带一个 RepositoryProvider,我现在问
我正在使用 Angular2 开发一个应用程序。 我正在尝试在我的应用程序中使用 Reactive Forms,但我遇到了一些错误: 第一个错误是关于 NgControl 的,如下所示: No pro
最近很多用户在使用电脑的时候发现了wmi provider host进程占用内存比较大,不知道这个进程到底是干什么的,能不能禁止,怎么禁止。下面来一起看看想想的介绍吧。 wmi provide
我的问题是: 当我在设计时不知道这些表达式的数量和类型时,如何将列表中的表达式拼接成一个引用? 在底部,我包含了类型提供程序的完整代码。 (我已经剥离了这个概念来证明这个问题。)我的问题出现在这些行:
我目前正在学习使用 Flutter 进行应用程序开发,并已开始学习 Provider 包。我遇到了一些困难并收到错误: “在此...小部件之上找不到正确的提供者” 我最终移动了 Provider 小部
我是 android 的新手,我正在学习如何使用 JavaMail API 发送电子邮件的教程,我已经正确添加了必要的 Jar,但我总是遇到无法解析 GmailSender 类上的符号提供程序,我尝试
我正在我的 Angular 应用程序中进行单元测试,我正在使用 TestBed 方法, 我正在测试组件,所以每个规范文件看起来像这样 import... describe('AppComponent'
enter image description here 代码:这是我的 index.js 文件 index.js import { Provider } from "react-redux"
Microsoft ASP.NET Universal Providers 1.1昨天与System.Web.Providers 1.2一起发布.在后面的 nuget 页面上声明:Legacy pac
在我的 Next js 项目中,我使用了 Next auth,其中 import {Provider} from 'next-auth/client' , 并包裹 在 _app.js 中。 但是,与此
当我在 View 模型中使用如下界面时 class MainViewModel @ViewModelInject constructor( private val trafficImagesR
更新 - 我实际上发现它是 Flutter Issue . 我有两个 Provider,一个是 EntriesProvider,另一个是 EntryProvider。我在创建条目时使用我的 Entry
function configure($provide, $injector) { $provide.provider("testservice", function () {
这真让我抓狂。我似乎无法弄清楚这有什么问题。 代码: public interface IMinutesCounter { void startTimer(); void stopTi
我在我的项目中玩 Dagger 2,然后我陷入了这个错误编译。-> Error:(18, 21) error: ....MyManager cannot be provided without an
我有一个 Resteasy 应用程序,它使用 Spring 并包含 ContainerRequestFilter 和 ContainerResponseFilter 实现,并用 @Provider 注
我正在尝试使用 Dagger2 设置一个新项目,我以前使用过 Dagger2,但现在我正在尝试自己从头开始设置它。我正在从我参与的 Kotlin 项目中获取示例,但无法像现在在 Kotlin 中一样为
我刚开始学习 dagger2,遇到了一个奇怪的问题,在我看来像是一个错误。这是模块: @Module public class SimpleModule { @Provides Coo
我是一名优秀的程序员,十分优秀!