Instance ID API
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
借助 Instance ID API,您可以将 Instance ID 与 Android 或 iOS 应用集成。Instance ID 可为应用的每个实例提供唯一标识符,并提供用于对操作进行身份验证和授权的机制。InstanceID
是长期有效的,但可能会因以下原因而过期:
- 将设备恢复出厂设置。
- 用户卸载应用。
- 用户在应用中执行“清除数据”操作。
- 设备长时间未使用(具体时长取决于设备和地区)。
- 实例 ID 服务会检测滥用行为或错误,并重置
InstanceID
。
- 如果您的客户端应用需要该功能,则需要服务器端代码。
实例 ID 服务会通过对 InstanceIDListenerService
的回调通知您的应用 InstanceID
已重置。如果您的应用收到此通知,则必须调用 getToken()
并检索新的 InstanceID
,然后更新其服务器。
使用 getToken
方法证明 InstanceID
的所有权,并允许服务器访问与应用关联的数据或服务。该方法遵循 OAuth2 的模式,并且需要 authorizedEntity
和 scope
。authorizedEntity
可以是项目 ID 或其他 InstanceID
,它决定了哪些服务有权使用生成的令牌。scope
用于确定令牌允许访问的特定服务或数据。
详细了解适用于以下情况的 Instance ID API:
Android
iOS
服务器
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Instance ID API provides a unique identifier for each app instance and enables authentication and authorization.\u003c/p\u003e\n"],["\u003cp\u003eInstance IDs are long-lived but can expire due to various factors like device reset, uninstallation, data clearing, extended inactivity, or service-detected issues.\u003c/p\u003e\n"],["\u003cp\u003eUpon Instance ID reset, apps are notified and must retrieve a new ID using \u003ccode\u003egetToken()\u003c/code\u003e and update their servers.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003egetToken()\u003c/code\u003e method, using OAuth2 patterns, verifies Instance ID ownership and grants server access to associated data or services based on authorized entity and scope.\u003c/p\u003e\n"]]],[],null,["# Instance ID API\n\nThe Instance ID API lets you integrate Instance ID with your Android\nor iOS app. Instance ID provides a unique identifier for each instance of\nyour app and a mechanism to authenticate and authorize actions. The `InstanceID` is long\nlived, but may expire for the following reasons:\n\n- Device factory reset.\n- User uninstalls the app.\n- User performs \"Clear Data\" in the app.\n- Device unused for an extended period (device and region determines the timespan).\n- Instance ID service detects abuse or errors and resets the `InstanceID`.\n- Server-side code if your client app requires that functionality.\n\nThe Instance ID service notifies your app of an `InstanceID` reset via\ncallback to a `InstanceIDListenerService`. If your app receives this\nnotification, it must call `getToken()` and retrieve the new `InstanceID`,\nand update its servers.\n\nUse the `getToken` method to prove the ownership of the `InstanceID` and to allow\nservers to access data or services associated with the app. The method follows\nthe patterns of OAuth2, and requires an `authorizedEntity` and `scope`. The\n`authorizedEntity` can be a project ID or another `InstanceID`, and it determines\nthe services that are authorized to use the generated token. The `scope`\ndetermines the specific service or data to which the token allows access.\n\nLearn more about the Instance ID API for:\n\n[Android](/instance-id/reference/android/api)\n[iOS](/instance-id/reference/ios/api)\n[Server](/instance-id/reference/server)"]]