Firebase-找不到GetTokenResult,getExpirationTimestamp() [英] Firebase - GetTokenResult, getExpirationTimestamp() not found

查看:86
本文介绍了Firebase-找不到GetTokenResult,getExpirationTimestamp()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试下面的代码来为Firebase用户获取令牌及其过期时间:

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;
    }
}

但是根据 GetTokenResult类引用应该有getExpirationTimestamp()方法:

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

getExpirationTimestamp()返回自纪元以来的时间(以毫秒为单位) 该ID令牌将在此过期

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

我在这里错过了什么吗?

Am I missing anything over here?

推荐答案

我尝试过,代码编译良好. 这是我项目中的firebase版本,请尝试设置相同版本

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'

这篇关于Firebase-找不到GetTokenResult,getExpirationTimestamp()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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