Tạo thông tin xác thực API REST của Google Wallet
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.
Google Wallet cung cấp một API REST cho phép bạn tạo và quản lý thẻ và vé bằng cách gửi các yêu cầu đến API Google Wallet qua HTTP. Điều này rất hữu ích đối với những ai muốn xây dựng các dịch vụ phía máy chủ để xử lý thẻ và vé theo phương thức lập trình.
Để sử dụng API REST của Google Wallet, bạn phải bật API trong bảng điều khiển Google Cloud, tạo tài khoản dịch vụ Google Cloud, sau đó tạo khoá cho tài khoản dịch vụ.
Khi bạn tạo thẻ và vé bằng API REST, khoá tài khoản dịch vụ dùng để ký các đối tượng được mã hoá bằng mã thông báo web JSON.
Đối với các thao tác khác, chẳng hạn như cập nhật hoặc xoá thẻ và vé, khoá tài khoản dịch vụ sẽ được gửi cùng với yêu cầu xác thực bạn là Bên phát hành thẻ và vé.
1. Bật API REST của Google Wallet
Để bật API REST của Google Wallet, hãy làm như sau:
- Nếu bạn chưa có tài khoản Google Cloud, hãy chuyển đến bảng điều khiển Google Cloud rồi làm theo các bước để đăng ký tài khoản mới.
- Trên trình đơn thả xuống của dự án ở đầu bảng điều khiển, hãy chọn dự án Google Cloud mà bạn muốn sử dụng hoặc tạo một dự án mới.
- Chuyển đến trang chi tiết sản phẩm API Google Wallet trong Marketplace của bảng điều khiển Google Cloud.
- Nhấp vào nút "Enable" (Bật). API REST của Google Wallet sẽ có sẵn cho dự án Google Cloud đã chọn sau giây lát.
2. Tạo khoá tài khoản dịch vụ Google Cloud
Để xác thực các yêu cầu tới API REST của Google Wallet, bạn cần tạo tài khoản dịch vụ và tạo khoá tài khoản dịch vụ bằng cách thực hiện các bước sau:
- Truy cập vào trang "Tạo tài khoản dịch vụ" trong bảng điều khiển Google Cloud.
- Điền thông tin chi tiết về tài khoản dịch vụ. Xin lưu ý địa chỉ email của tài khoản dịch vụ xuất hiện bên dưới trường "Mã tài khoản dịch vụ". Bạn sẽ cần điều này sau này khi sử dụng tài khoản dịch vụ để xác thực yêu cầu của mình với API REST của Google Wallet.
- Nhấp vào nút "XONG". Bạn không cần hoàn tất các bước tạo tài khoản dịch vụ khác.
- Nhấp vào mục trong trình đơn "KHOÁ" ở đầu trang.
- Nhấp vào trình đơn thả xuống "THÊM khoá", rồi nhấp vào "Tạo khoá mới".
- Chọn loại khoá "JSON".
- Nhấp vào "TẠO" để tạo và tải khoá tài khoản dịch vụ xuống.
3. Uỷ quyền tài khoản dịch vụ trong bảng điều khiển Google Wallet
Để xác thực các yêu cầu của bạn với API REST của Google Wallet bằng khoá tài khoản dịch vụ, bạn phải thêm địa chỉ email của tài khoản dịch vụ của bạn với tư cách là người dùng vào tài khoản của công ty phát hành. Để thêm tài khoản dịch vụ làm người dùng, hãy làm như sau:
- Truy cập vào trang "Tài khoản dịch vụ" trong bảng điều khiển Google Cloud.
- Sao chép địa chỉ email của tài khoản dịch vụ bạn muốn sử dụng để xác thực yêu cầu của bạn với Google Wallet API.
- Chuyển đến bảng điều khiển Google Pay và Wallet.
- Trong điều hướng bên trái, nhấp vào "Người dùng".
- Nhấp vào "Mời người dùng".
- Nhập địa chỉ email của tài khoản dịch vụ của bạn.
- Trong trình đơn thả xuống "Cấp truy cập", hãy chọn "Nhà phát triển".
- Nhấp vào nút "Mời".
Sau khi thêm tài khoản dịch vụ, bạn có thể sử dụng bất kỳ khoá tài khoản dịch vụ nào được tạo cho tài khoản đó để xác thực các yêu cầu đến API REST của Google Wallet. Khi sử dụng khoá tài khoản dịch vụ, xin lưu ý rằng đây là những thông tin xác thực có mức độ nhạy cảm cao chỉ nên được dùng trong môi trường bảo mật phía 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-29 UTC.
[null,null,["Cập nhật lần gần đây nhất: 2025-08-29 UTC."],[[["\u003cp\u003eGoogle Wallet's REST API enables programmatic management of passes via HTTP requests.\u003c/p\u003e\n"],["\u003cp\u003eTo use the API, you must enable it in Google Cloud Console, create a service account, and generate a key.\u003c/p\u003e\n"],["\u003cp\u003eThe service account key is used for authentication when creating, updating, or deleting passes.\u003c/p\u003e\n"],["\u003cp\u003eEnsure your service account is authorized as a 'Developer' in the Google Pay & Wallet console to authenticate requests.\u003c/p\u003e\n"]]],["The Google Wallet REST API allows programmatic pass management via HTTP requests. To use it, enable the API in the Google Cloud console, create a service account, and generate a JSON key. This key is used to sign JSON Web Token-encoded Pass Objects for creation and authenticates requests for updates or deletions. Finally, authorize the service account by adding its email as a 'Developer' user in the Google Pay & Wallet console. This process enables secure, server-side interaction with the Google Wallet.\n"],null,["# Generating Google Wallet REST API authentication credentials\n\nGoogle Wallet offers a REST API that lets you create and manage passes by\nsending requests to the Google Wallet API over HTTP. This is useful for those who\nwant to build server-side services to work with passes programmatically.\n\nTo use the Google Wallet REST API, you must enable the API in the Google Cloud console,\ncreate a Google Cloud service account, then generate a key for the service account.\n\nWhen you create passes with the REST API, the service account key used to sign your\nJSON Web Token-encoded Passes Objects.\n\nFor other operations, such as updating or deleting passes, the service account key\nis sent with the request to authenticate you as the Pass Issuer.\n\n1. Enable the Google Wallet REST API\n------------------------------------\n\nTo enable the Google Wallet REST API, do the following:\n\n1. If you don't already have a Google Cloud account, go to the [Google Cloud console](https://console.cloud.google.com) and follow the steps to register for a new account.\n2. From the project drop-down menu at the top of the console, select the Google Cloud project you want to use, or create a new one.\n3. Go to the [Google Wallet API product details page](https://console.cloud.google.com/apis/library/walletobjects.googleapis.com) in the Google Cloud console Marketplace.\n4. Click the 'Enable' button. In a few moments, the Google Wallet REST API will be available for the selected Google Cloud project.\n\n2. Generate a Google Cloud service account key\n----------------------------------------------\n\nTo authenticate requests to the Google Wallet REST API, you'll need to create a\nservice account, and generate a service account key by doing the following:\n\n1. Go to the ['Create service account' page](https://console.cloud.google.com/iam-admin/serviceaccounts/create) in the Google Cloud console.\n2. Fill in the service account details. Note the email address for the service account that appears below the 'Service account ID' field. You will need this later when you use the service account to authenticate your requests to the Google Wallet REST API.\n3. Click the 'DONE' button. There is no need to complete the other service account creation steps.\n4. Click the 'KEYS' menu item at the top of the page.\n5. Click the 'ADD KEY' drop-down menu, then click 'Create new key'.\n6. Select key type 'JSON'.\n7. Click 'CREATE' to create and download the service account key.\n\n3. Authorize your service account in the Google Wallet console\n--------------------------------------------------------------\n\nTo authenticate your requests to the Google Wallet REST API using a service account\nkey, you must add the email address of your service account as a user to your\nIssuer account. To add your service account as a user, do the following:\n\n1. Go to the ['Service accounts'](https://console.cloud.google.com/iam-admin/serviceaccounts) page in the Google Cloud console.\n2. Copy the email address of the service account you want to use to authenticate your requests to the Google Wallet API.\n3. Go to the [Google Pay \\& Wallet console](https://pay.google.com/business/console/).\n4. In the left nav, click 'Users'.\n5. Click 'Invite a user'.\n6. Input the email address of your service account.\n7. In the 'Access level' drop-down, select 'Developer'.\n8. Click the 'Invite' button.\n\nOnce your service account is added, you can use any service account keys generated\nfor it to authenticate requests to the Google Wallet REST API. When using service\naccount keys, keep in mind that these are highly sensitive credentials that\nshould only be used in secure, server-side environments."]]