Instance ID API (API Mã phiên bản)
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
API Mã phiên bản cho phép bạn tích hợp Mã phiên bản với ứng dụng Android hoặc iOS. Mã phiên bản cung cấp một giá trị nhận dạng duy nhất cho mỗi phiên bản của ứng dụng và một cơ chế để xác thực và uỷ quyền các hành động. InstanceID
có thời gian hoạt động lâu dài nhưng có thể hết hạn vì những lý do sau:
- Đặt lại thiết bị về trạng thái ban đầu.
- Người dùng gỡ cài đặt ứng dụng.
- Người dùng thực hiện thao tác "Xoá dữ liệu" trong ứng dụng.
- Thiết bị không được sử dụng trong một khoảng thời gian dài (thiết bị và khu vực xác định khoảng thời gian).
- Dịch vụ mã nhận dạng thực thể phát hiện hành vi sai trái hoặc lỗi và đặt lại
InstanceID
.
- Mã phía máy chủ nếu ứng dụng khách của bạn yêu cầu chức năng đó.
Dịch vụ Mã phiên bản sẽ thông báo cho ứng dụng của bạn về việc đặt lại InstanceID
thông qua lệnh gọi lại đến InstanceIDListenerService
. Nếu nhận được thông báo này, ứng dụng của bạn phải gọi getToken()
và truy xuất InstanceID
mới, đồng thời cập nhật máy chủ của ứng dụng.
Sử dụng phương thức getToken
để chứng minh quyền sở hữu InstanceID
và cho phép máy chủ truy cập vào dữ liệu hoặc dịch vụ liên kết với ứng dụng. Phương thức này tuân theo các mẫu của OAuth2 và yêu cầu authorizedEntity
và scope
. authorizedEntity
có thể là mã dự án hoặc một InstanceID
khác và xác định các dịch vụ được uỷ quyền sử dụng mã thông báo đã tạo. scope
xác định dịch vụ hoặc dữ liệu cụ thể mà mã thông báo cho phép truy cập.
Tìm hiểu thêm về API Mã phiên bản để:
Android
iOS
Máy chủ
Trừ phi có lưu ý khác, nội dung của trang này được cấp phép theo Giấy phép ghi nhận tác giả 4.0 của Creative Commons và các mẫu mã lập trình được cấp phép theo Giấy phép Apache 2.0. Để biết thông tin chi tiết, vui lòng tham khảo Chính sách trang web của Google Developers. Java là nhãn hiệu đã đăng ký của Oracle và/hoặc các đơn vị liên kết với Oracle.
Cập nhật lần gần đây nhất: 2025-08-31 UTC.
[null,null,["Cập nhật lần gần đây nhất: 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)"]]