產生 Google Wallet REST API 驗證憑證
透過集合功能整理內容
你可以依據偏好儲存及分類內容。
Google 錢包提供 REST API,可讓您透過 HTTP 將要求傳送至 Google Wallet API,即可建立及管理票證。如果您想建構伺服器端服務,以程式輔助方式使用票證,這項功能就非常實用。
如要使用 Google Wallet REST API,您必須在 Google Cloud 控制台中啟用 API、建立 Google Cloud 服務帳戶,然後產生該服務帳戶的金鑰。
使用 REST API 建立票證時,這是指用來簽署 JSON Web Token 編碼票證物件的服務帳戶金鑰。
如果是其他作業 (例如更新或刪除票證),系統會傳送要求,同時傳送服務帳戶金鑰,讓您驗證票證核發者。
1. 啟用 Google Wallet REST API
如要啟用 Google Wallet REST API,請按照下列步驟操作:
- 如果您還沒有 Google Cloud 帳戶,請前往 Google Cloud 控制台,然後按照步驟註冊新帳戶。
- 在主控台頂端的專案下拉式選單中,選取要使用的 Google Cloud 專案,或是建立新專案。
- 前往 Google Cloud 控制台 Marketplace 的 Google Wallet API 產品詳細資料頁面。
- 按一下「啟用」按鈕。稍後,所選的 Google Cloud 專案將可支援 Google Wallet REST API。
2. 產生 Google Cloud 服務帳戶金鑰
如要驗證向 Google Wallet REST API 發出的要求,請建立服務帳戶,並按照下列步驟產生服務帳戶金鑰:
- 前往 Google Cloud 控制台的「建立服務帳戶」頁面。
- 填寫服務帳戶詳細資料。請注意「服務帳戶 ID」欄位下方顯示的服務帳戶電子郵件地址。稍後使用服務帳戶驗證傳送至 Google Wallet REST API 的要求時,需要用到這項資訊。
- 按一下「完成」按鈕。您不需要完成其他服務帳戶建立步驟。
- 按一下頁面頂端的「金鑰」選單項目。
- 按一下「新增金鑰」下拉式選單,然後點選「建立新的金鑰」。
- 選取金鑰類型「JSON」。
- 按一下「建立」即可建立並下載服務帳戶金鑰。
3. 在 Google 錢包控制台中授權服務帳戶
如要使用服務帳戶金鑰驗證傳送至 Google Wallet REST API 的要求,您必須將服務帳戶的電子郵件地址新增為核發者帳戶的使用者。如要將服務帳戶新增為使用者,請按照下列步驟操作:
- 前往 Google Cloud 控制台的「Service accounts」(服務帳戶) 頁面。
- 複製您要用來驗證 Google Wallet API 要求的服務帳戶電子郵件地址。
- 前往 Google Pay 和錢包主控台。
- 在左側導覽列中,按一下 [使用者]。
- 按一下「邀請使用者」。
- 輸入服務帳戶的電子郵件地址。
- 在「存取層級」下拉式選單中,選取「開發人員」。
- 按一下 [邀請] 按鈕。
新增服務帳戶後,您就能使用任何為其產生的服務帳戶金鑰驗證對 Google Wallet REST API 的要求。使用服務帳戶金鑰時,請記得這些是高度機密的憑證,請只用於安全的伺服器端環境。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-29 (世界標準時間)。
[null,null,["上次更新時間:2025-08-29 (世界標準時間)。"],[[["\u003cp\u003eGoogle Wallet's REST API enables programmatic management of passes via HTTP requests, ideal for server-side integrations.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize the API, enable it in the Google Cloud console, create a service account, and generate a key for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThis service account key is crucial for signing JWT-encoded Passes Objects during creation and for authenticating other operations like updates and deletions.\u003c/p\u003e\n"],["\u003cp\u003eGranting 'Developer' access to the service account in the Google Pay & Wallet console authorizes API 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."]]