除了提供用于身份验证的唯一 ID 之外,实例 ID 还可以生成安全令牌,以便与其他服务搭配使用。其他功能包括:
生成安全令牌
实例 ID 提供了一个简单的 API,用于生成安全令牌,以授权第三方访问应用的服务器端管理资源。
验证应用的真实性
将实例 ID 令牌传递给您的服务器,并使用实例 ID 服务验证应用软件包名称并检查其是否具有有效的签名。使用实例 ID Cloud 服务验证令牌有助于识别已知应用。为了降低费用并减少冗余的往返通信,请将服务器配置为存储这些令牌,以便只需进行一次检查。如果出现安全问题,您的应用可以删除令牌或实例 ID 本身,并生成新的令牌或实例 ID。此外,如果实例 ID 服务器检测到 bug 或安全问题,则会发起令牌或实例 ID 刷新。
确认应用设备处于活动状态
Instance ID 服务器可以告诉您安装了您应用的设备上次使用的时间。您可以根据此参数来决定是保留应用中的数据,还是发送推送消息以重新吸引用户。
识别和跟踪应用
实例 ID 在全球所有应用实例中都是唯一的,因此您的数据库可以使用它来唯一标识和跟踪应用实例。您的服务器端代码可以通过实例 ID 云服务验证实例 ID 是否真实,以及该 ID 是否与在您的服务器上注册的原始应用相同。出于隐私保护考虑,您的应用可以删除实例 ID,使其不再与数据库中的任何历史记录相关联。当您的应用下次调用实例 ID 时,将会获得一个全新的实例 ID,与之前的实例 ID 没有任何关系。
实例 ID 生命周期
当您的应用上线时,实例 ID 服务会发出 InstanceID。InstanceID 由公钥/私钥对提供支持,私钥存储在本地设备上,公钥已注册到实例 ID 服务。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003e\u003cstrong\u003eWarning:\u003c/strong\u003e The Instance ID API is deprecated; for unique app installation identifiers, use the Firebase installations API instead.\u003c/p\u003e\n"],["\u003cp\u003eInstance ID offers key features like generating security tokens, verifying app authenticity, confirming app device activity, and identifying/tracking apps.\u003c/p\u003e\n"],["\u003cp\u003eInstance ID has a lifecycle involving issuing an ID, requesting fresh IDs and tokens, storing them on the server (optional), and handling token refreshes.\u003c/p\u003e\n"],["\u003cp\u003eClient implementation requires including the appropriate library and potentially a Project ID for token generation.\u003c/p\u003e\n"],["\u003cp\u003eFor detailed instructions, refer to the Android and iOS implementation guides.\u003c/p\u003e\n"]]],[],null,["# What is Instance ID?\n\n| **Warning:** The Instance ID API is deprecated. If you need to access unique app installation identifiers, use the [Firebase installations](//firebase.google.com/docs/projects/manage-installations) API. See also [Firebase installations and Instance ID](//firebase.google.com/docs/projects/manage-installations#fid-iid). The [server-side topic management API](https://developers.google.com/instance-id/reference/server#create_relationship_maps_for_app_instances) is still available.\n\nKey features\n------------\n\nIn addition to providing unique IDs for authentication, Instance ID\ncan generate security tokens for use with other services. Other features\ninclude:\n\n### Generate Security Tokens\n\n: Instance ID provides a simple API to generate security tokens that\n authorize third parties to access your app's server side managed resources.\n\n### Verify app authenticity\n\n: Pass Instance ID tokens to your server and use the Instance ID\n service to verify the app package name and check if it has a valid signature.\n Verifying tokens with the Instance ID Cloud Service helps identify known\n apps. To reduce cost and redundant round trip communications, configure your\n server to store these tokens so the check is needed only once.\n In the event of a security concern, your app can delete tokens, or\n Instance ID itself, and generate new ones. In addition, the\n Instance ID server initiates token or Instance ID refresh if it\n detects bugs or security issues.\n\n### Confirm app device is active\n\n: The Instance ID server can tell you when the device on which your app\n is installed was last used. Use this to decide whether to keep data from your\n app or send a push message to reengage with your users.\n\n### Identify and track apps\n\n: Instance ID is unique across all app instances across the world, so\n your database can use it to uniquely identify and track app instances. Your\n server-side code can verify, via the Instance ID cloud service, that an\n Instance ID is genuine and is the same ID as the original app that\n registered with your server. For privacy, your app can delete an Instance ID so\n it is no longer associated with any history in the database. The next time your\n app calls Instance ID it will get an entirely new Instance ID with no\n relationship to its previous one.\n\nInstance ID lifecycle\n---------------------\n\n1. The Instance ID service issues an `InstanceID` when your app comes online. The `InstanceID` is backed by a public/private key pair with the private key stored on the local device and the public key registered with the Instance ID service.\n2. Your app can request a fresh `InstanceID` whenever needed using the `getID()` method. Your app can store it on your server if you have one that supports your app.\n3. Your app can request tokens from the Instance ID service as needed using the `getToken()` method, and like `InstanceID`, your app can also store tokens on your own server. All tokens issued to your app belong to the app's `InstanceID`.\n4. Tokens are unique and secure, but your app or the Instance ID service may need to refresh tokens in the event of a security issue or when a user uninstalls and reinstalls your app during device restoration. Your app must implement a listener to respond to token refresh requests from the Instance ID service.\n\nClient implementation\n---------------------\n\nInstance ID runs on both Android and iOS. Each requires you to include\nthe appropriate library in your client app. Android requires\n[Google Play Services](https://developer.android.com/google/play-services/index.html). You will need a Project ID generated\nby the [](/console/help/new)[Google Developers Console](https://console.developers.google.com/project) if you intend\nto generate tokens.\n\nFor detailed instructions, see the [Android](/instance-id/guides/android-implementation)\nand [iOS](/instance-id/guides/ios-implementation) implementation guides."]]