API mã thực thể không được dùng nữa. Nếu bạn cần truy cập vào giá trị nhận dạng cài đặt ứng dụng duy nhất, hãy sử dụng API Cài đặt Firebase. Xem thêm bài viết Cài đặt Firebase và 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.
Tính năng chính
Ngoài việc cung cấp mã nhận dạng duy nhất để xác thực, Mã nhận dạng thực thể còn có thể tạo mã thông báo bảo mật để sử dụng với các dịch vụ khác. Các tính năng khác bao gồm:
Tạo mã thông báo bảo mật
Mã nhận dạng thực thể cung cấp một API đơn giản để tạo mã thông báo bảo mật, cho phép bên thứ ba truy cập vào các tài nguyên do phía máy chủ của ứng dụng quản lý.
Xác minh tính xác thực của ứng dụng
Chuyển mã thông báo Mã phiên bản đến máy chủ của bạn và sử dụng dịch vụ Mã phiên bản để xác minh tên gói ứng dụng và kiểm tra xem tên gói đó có chữ ký hợp lệ hay không.
Việc xác minh mã thông báo bằng Dịch vụ đám mây mã nhận dạng thực thể giúp xác định các ứng dụng đã biết. Để giảm chi phí và giao tiếp qua lại thừa, hãy định cấu hình máy chủ để lưu trữ các mã thông báo này để chỉ cần kiểm tra một lần.
Trong trường hợp có vấn đề về bảo mật, ứng dụng của bạn có thể xoá mã thông báo hoặc chính mã nhận dạng thực thể và tạo mã thông báo mới. Ngoài ra, máy chủ Mã phiên bản sẽ bắt đầu làm mới mã thông báo hoặc Mã phiên bản nếu phát hiện lỗi hoặc vấn đề bảo mật.
Xác nhận thiết bị ứng dụng đang hoạt động
Máy chủ Mã phiên bản có thể cho bạn biết thời điểm thiết bị cài đặt ứng dụng của bạn được sử dụng lần cuối. Hãy sử dụng thông tin này để quyết định giữ lại dữ liệu từ ứng dụng của bạn hay gửi thông báo đẩy để tương tác lại với người dùng.
Xác định và theo dõi ứng dụng
Mã thực thể là duy nhất trên tất cả các thực thể ứng dụng trên thế giới, vì vậy, cơ sở dữ liệu của bạn có thể sử dụng mã này để xác định và theo dõi các thực thể ứng dụng một cách riêng biệt. Mã phía máy chủ của bạn có thể xác minh, thông qua dịch vụ đám mây Mã nhận dạng thực thể, rằng một Mã nhận dạng thực thể là chính hãng và giống với mã nhận dạng của ứng dụng ban đầu đã đăng ký với máy chủ của bạn. Để bảo vệ quyền riêng tư, ứng dụng của bạn có thể xoá Mã phiên bản để mã này không còn liên kết với bất kỳ nhật ký nào trong cơ sở dữ liệu. Lần tiếp theo ứng dụng gọi Mã phiên bản, ứng dụng sẽ nhận được một Mã phiên bản hoàn toàn mới không có mối quan hệ nào với mã phiên bản trước đó.
Vòng đời của mã phiên bản
Dịch vụ Mã bản sao sẽ phát hành InstanceID khi ứng dụng của bạn có kết nối mạng.
InstanceID được hỗ trợ bởi một cặp khoá công khai/riêng tư, trong đó khoá riêng tư được lưu trữ trên thiết bị cục bộ và khoá công khai được đăng ký với dịch vụ Mã nhận dạng thực thể.
Ứng dụng của bạn có thể yêu cầu một InstanceID mới bất cứ khi nào cần bằng cách sử dụng phương thức getID(). Ứng dụng của bạn có thể lưu trữ mã này trên máy chủ nếu bạn có máy chủ hỗ trợ ứng dụng.
Ứng dụng của bạn có thể yêu cầu mã thông báo từ dịch vụ Mã nhận dạng thực thể khi cần bằng cách sử dụng phương thức getToken(). Giống như InstanceID, ứng dụng của bạn cũng có thể lưu trữ mã thông báo trên máy chủ của riêng mình. Tất cả mã thông báo được cấp cho ứng dụng của bạn đều thuộc về InstanceID của ứng dụng.
Mã thông báo là duy nhất và an toàn, nhưng ứng dụng hoặc dịch vụ Mã nhận dạng thực thể của bạn có thể cần làm mới mã thông báo trong trường hợp xảy ra sự cố bảo mật hoặc khi người dùng gỡ cài đặt và cài đặt lại ứng dụng của bạn trong quá trình khôi phục thiết bị. Ứng dụng của bạn phải triển khai trình nghe để phản hồi các yêu cầu làm mới mã thông báo từ dịch vụ Mã nhận dạng thực thể.
Triển khai ứng dụng
Mã phiên bản chạy trên cả Android và iOS. Mỗi ứng dụng yêu cầu bạn đưa thư viện thích hợp vào ứng dụng khách. Android yêu cầu Dịch vụ Google Play. Bạn sẽ cần có Mã dự án do Google Developers Console tạo nếu có ý định tạo mã thông báo.
Để biết hướng dẫn chi tiết, hãy xem hướng dẫn triển khai Android và iOS.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-31 UTC."],[[["\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."]]