執行個體 ID API
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
您可以使用 Instance ID API 將 Instance ID 與 Android 或 iOS 應用程式整合。Instance ID 會為應用程式的每個執行個體提供專屬 ID,以及驗證和授權動作的機制。InstanceID
的生命週期很長,但可能會因下列原因而到期:
- 將裝置恢復原廠設定。
- 使用者解除安裝應用程式。
- 使用者在應用程式中執行「清除資料」功能。
- 裝置長時間未使用 (裝置和地區決定時間範圍)。
- 執行個體 ID 服務偵測到濫用或錯誤情形,並重設
InstanceID
。
- 如果用戶端應用程式需要這項功能,則為伺服器端程式碼。
執行個體 ID 服務會透過回呼通知 InstanceIDListenerService
,讓應用程式知道 InstanceID
已重設。如果應用程式收到這項通知,就必須呼叫 getToken()
並擷取新的 InstanceID
,然後更新伺服器。
使用 getToken
方法證明 InstanceID
的擁有權,並允許伺服器存取與應用程式相關聯的資料或服務。此方法遵循 OAuth2 的模式,且需要 authorizedEntity
和 scope
。authorizedEntity
可以是專案 ID 或其他 InstanceID
,可決定哪些服務獲授權使用產生的權杖。scope
會決定權杖允許存取的特定服務或資料。
進一步瞭解以下項目的 Instance ID API:
Android
iOS
伺服器
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-31 (世界標準時間)。
[null,null,["上次更新時間: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)"]]