Firebase - GetTokenResult, getExpirationTimestamp() not found

梦想与她 提交于 2021-01-27 19:48:12

问题


I am trying below code to obtain token and its expiration time for a Firebase user:

fun refreshToken(apiBlock: (() -> Unit)? = null) {
    val firebaseUser = FirebaseAuth.getInstance().currentUser
    if (firebaseUser != null) {
        firebaseUser.getIdToken(false)
                .addOnCompleteListener { task ->
                    if (task.isSuccessful) {
                        generatedToken = task.result.token
                        val tokenExpirationTime = task.result.expirationTimestamp
                        apiBlock?.invoke()
                    } else {
                        // Handle error -> task.getException();
                    }
                }
    }
}

However I am getting compilation error at following line:

val tokenExpirationTime = task.result.expirationTimestamp

When I tried to check the existence of this method in decompiled class, I could not get any such method:

package com.google.firebase.auth;

import android.support.annotation.Nullable;
import com.google.android.gms.common.internal.Hide;

public class GetTokenResult {
    private String zzeia;

    @Hide
    public GetTokenResult(String var1) {
        this.zzeia = var1;
    }

    @Nullable
    public String getToken() {
        return this.zzeia;
    }
}

However as per GetTokenResult class reference there should be getExpirationTimestamp() method:

getExpirationTimestamp() Returns the time in milliseconds since epoch at which this ID token will expire

Am I missing anything over here?


回答1:


I tried it, the code compiles well. This is firebase version in my project, try to set the same

implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-auth:16.0.3'


来源:https://stackoverflow.com/questions/52690267/firebase-gettokenresult-getexpirationtimestamp-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!