instanceId和getIdToken有什么区别 [英] What's the difference between instanceId and getIdToken

查看:89
本文介绍了instanceId和getIdToken有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白两者之间有什么区别

I don't understand what's the difference between:

FirebaseAuth.getInstance().currentUser.getIdToken(true).addOnSuccessListener {
    Log.d("tag",it.token) // token #1
} 



FirebaseInstanceId.getInstance().instanceId.addOnSuccessListener {
    Log.d("tag", it.token) //token #2
}


这两种方法都返回一些令牌,它们之间有什么区别?


Both of these methods return some token, what is the difference between them?

推荐答案

getIdToken(boolean forceRefresh)

为用户获取Firebase身份ID令牌;在针对自己的后端进行身份验证时非常有用.

Fetches a Firebase Auth ID Token for the user; useful when authenticating against your own backend.

getIdToken在类FirebaseUser中,当您使用自己的服务器时,您可以使用令牌对用户进行身份验证.

The getIdToken is in class FirebaseUser, you use the token to authenticate the user when you are using your own server.

getInstanceId()返回您下载的应用程序的ID,在FCM中也使用该ID,以便能够将通知发送到已下载该应用程序的特定手机.

getInstanceId() returns the id of the app that you downloaded, it is also used in FCM to be able to send notifications to a specific phone that has the app downloaded.

实例ID稳定,除了以下情况:

Instance ID is stable except when:

  1. 应用程序删除实例ID
  2. 应用已在新设备上还原
  3. 用户卸载/重新安装应用程序
  4. 用户清除应用数据

https://firebase.google.com/docs/reference/android/com/google/firebase/iid/FirebaseInstanceId.html#getInstanceId()

这篇关于instanceId和getIdToken有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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