更新到新的SDK后,失去与Firebase数据库的连接 [英] Losing connection with Firebase database after updating to new SDK

查看:115
本文介绍了更新到新的SDK后,失去与Firebase数据库的连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更新我的项目Firebase SDK后,我注意到我的应用程序经常失去与Firebase数据库的连接。从几分钟到一个多小时的时间,将需要花费时间。一旦断开连接,应用程序将不会重新连接,直到我已经注销或清除应用程序数据。



在我失去连接之前,日志中的一个条目指出我的授权令牌已经过期:


PersistentConnection:pc_0 - Auth令牌被撤销:expired_token(Auth令牌已过期)

FYI Twitter和Facebook用于我的身份验证,并没有遇到与以前的Firebase SDK有关的问题。



我创建了一个新项目(使用简单的身份验证和实时数据库)问题依然存在,而且确实存在。我附上了这个新项目的片段:
$ b build.gradle

  apply plugin:'com.android.application'

android {
compileSdkVersion 23
buildToolsVersion23.0.3

defaultConfig {
applicationIdcom.sample.gideon.test
minSdkVersion 17
targetSdkVersion 23
versionCode 1
versionName1.0
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'),'proguard-rules.pro'
}



存储库{
mavenCentral()
}

依赖项{
编译fileTree(dir:' libs',包括:['* .jar'])
testCompile'junit:junit:4.12'
compile'c​​om.android.support:appcompat-v7:23.4.0'
compile com.android.support:support- v4:23.4.0'
compile'c​​om.facebook.android:facebook-android-sdk:4.12.0'
compile'c​​om.google.firebase:firebase-database:9.0.0'
compile'c​​om.google.firebase:firebase-auth:9.0.0'
compile'c​​om.android.support:design:23.4.0'
}

apply插件:'com.google.gms.google-services'

身份验证活动遵循firebase facebook登录指导,它确实成功地记录用户并将其发送到MainActivity,然后使用以下代码监视数据库连接:
$ b MainActivity

  DatabaseReference connectedRef = FirebaseDatabase.getInstance()。getReference(。info / connected); 
connectedRef.addValueEventListener(new ValueEventListener(){
@Override
public void onDataChange(DataSnapshot snapshot){
boolean connected = snapshot.getValue(Boolean.class);
如果(连接){
System.out.println(connected);
} else {
System.out.println(not connected);
}

$ b @Override
public void onCancelled(DatabaseError error){
System.err.println(Listener was canceled);
}
});

有谁知道是什么导致应用程序失去连接?到目前为止,在2个不同的项目中,有2个认证提供者(twitter和facebook),只有在更新到新的Firebase之后,才会出现错误。 解决方案

此页非常有用。尤其是由firebase团队为那些仍然遇到身份验证令牌问题的人员制作的疑难解答指南更新到9.0.2。


After updating my projects Firebase SDK, I noticed my app regularly lose connection with the firebase database. The time it would take to disconnect ranging from a few minutes to just over an hour. Once disconnected, the app would not reconnect until I have either logged out or cleared the apps data.

Also right before I lose connection, an entry in the log states that my auth token has expired:

PersistentConnection: pc_0 - Auth token revoked: expired_token (Auth token is expired.)

FYI, im using Twitter and Facebook for my authentication and did not experience such issues with the previous Firebase SDK.

I created a new project (with simple auth and real time database) to see if the issue persists and it does. I've attached snippets of that new project:

The build.gradle:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.3"

    defaultConfig {
        applicationId "com.sample.gideon.test"
        minSdkVersion 17
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

repositories {
    mavenCentral()
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.4.0'
    compile 'com.android.support:support-v4:23.4.0'
    compile 'com.facebook.android:facebook-android-sdk:4.12.0'
    compile 'com.google.firebase:firebase-database:9.0.0'
    compile 'com.google.firebase:firebase-auth:9.0.0'
    compile 'com.android.support:design:23.4.0'
}

apply plugin: 'com.google.gms.google-services'

The authentication activity follows the firebase facebook login guide, which indeed successfully logs the user in and sends them to the MainActivity which then monitors the database connection using the following code:

MainActivity

    DatabaseReference connectedRef = FirebaseDatabase.getInstance().getReference(".info/connected");
    connectedRef.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snapshot) {
            boolean connected = snapshot.getValue(Boolean.class);
            if (connected) {
                System.out.println("connected");
            } else {
                System.out.println("not connected");
            }
        }

        @Override
        public void onCancelled(DatabaseError error) {
            System.err.println("Listener was cancelled");
        }
    });

Would anyone know what is causing the app to lose connection? So far the error has been experienced in 2 different projects with 2 auth providers (twitter and facebook) and only after updating to the new Firebase.

解决方案

Firebase fixed the connection issue with the release of 9.0.2. Also for anyone still having trouble, I found the answer on this page very useful. Especially the troubleshoot guide produced by the firebase team for those still experiencing auth token issues after updating to 9.0.2.

这篇关于更新到新的SDK后,失去与Firebase数据库的连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆