问题
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