问题描述
我不明白两者之间有什么区别
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?
推荐答案
为用户获取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:
- 应用程序删除实例ID
- 应用已在新设备上还原
- 用户卸载/重新安装应用程序
- 用户清除应用数据
这篇关于instanceId和getIdToken有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!