API ของรหัสอินสแตนซ์
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
Instance ID API ช่วยให้คุณผสานรวม Instance ID กับแอป Android หรือ iOS ได้ Instance ID เป็นตัวระบุที่ไม่ซ้ำกันสำหรับอินสแตนซ์แต่ละรายการของแอป รวมถึงกลไกในการตรวจสอบสิทธิ์และอนุญาตการดำเนินการ InstanceID
มีอายุการใช้งานยาวนาน แต่อาจหมดอายุด้วยสาเหตุต่อไปนี้
- รีเซ็ตอุปกรณ์เป็นค่าเริ่มต้น
- ผู้ใช้ถอนการติดตั้งแอป
- ผู้ใช้ "ล้างข้อมูล" ในแอป
- อุปกรณ์ไม่ได้ใช้งานเป็นเวลานาน (อุปกรณ์และภูมิภาคเป็นตัวกำหนดช่วงเวลา)
- บริการรหัสอินสแตนซ์จะตรวจหาการละเมิดหรือข้อผิดพลาดและรีเซ็ต
InstanceID
- โค้ดฝั่งเซิร์ฟเวอร์หากแอปไคลเอ็นต์ต้องใช้ฟังก์ชันดังกล่าว
บริการ Instance ID จะแจ้งให้แอปทราบเกี่ยวกับการรีเซ็ต InstanceID
ผ่าน callback ไปยัง InstanceIDListenerService
หากแอปของคุณได้รับการแจ้งเตือนนี้ แอปจะต้องเรียกใช้ getToken()
และดึงข้อมูล InstanceID
ใหม่ รวมถึงอัปเดตเซิร์ฟเวอร์
ใช้วิธีการ getToken
เพื่อพิสูจน์ความเป็นเจ้าของ InstanceID
และอนุญาตให้เซิร์ฟเวอร์เข้าถึงข้อมูลหรือบริการที่เชื่อมโยงกับแอป วิธีการนี้เป็นไปตามรูปแบบของ OAuth2 และต้องอาศัย authorizedEntity
และ scope
authorizedEntity
อาจเป็นรหัสโปรเจ็กต์หรือ InstanceID
อื่นก็ได้ และจะเป็นตัวกำหนดบริการที่ได้รับอนุญาตให้ใช้โทเค็นที่สร้างขึ้น scope
จะกำหนดบริการหรือข้อมูลเฉพาะที่โทเค็นอนุญาตให้เข้าถึง
ดูข้อมูลเพิ่มเติมเกี่ยวกับ Instance ID API สำหรับ
Android
iOS
เซิร์ฟเวอร์
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\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)"]]