正在生成 Google Wallet REST API 身份验证凭据
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
Google 钱包提供了一个 REST API,可让您通过 HTTP 向 Google Wallet API 发送请求,从而创建和管理卡券。对于想要构建服务器端服务以以编程方式处理卡券的用户来说,这非常有用。
如需使用 Google Wallet REST API,您必须在 Google Cloud 控制台中启用该 API,创建 Google Cloud 服务帐号,然后为服务帐号生成密钥。
使用 REST API 创建卡券时,该服务帐号密钥用于对 JSON Web 令牌编码的卡券对象进行签名。
对于其他操作(例如更新或删除卡券),服务帐号密钥会与请求一起发送,以验证您作为卡券颁发者的身份。
1. 启用 Google Wallet REST API
如需启用 Google Wallet REST API,请执行以下操作:
- 如果您还没有 Google Cloud 帐号,请前往 Google Cloud 控制台,然后按照相关步骤注册新帐号。
- 从控制台顶部的项目下拉菜单中,选择要使用的 Google Cloud 项目,或创建一个新项目。
- 前往 Google Cloud 控制台 Marketplace 中的 Google Wallet API 商品详情页面。
- 点击“启用”按钮。稍后,Google Wallet REST API 将可用于所选的 Google Cloud 项目。
2. 生成 Google Cloud 服务账号密钥
要对向 Google Wallet REST API 发出的请求进行身份验证,您需要创建一个服务帐号,然后通过执行以下操作生成服务帐号密钥:
- 前往 Google Cloud 控制台中的“创建服务帐号”页面。
- 填写服务账号详细信息。记下“服务帐号 ID”字段下方显示的服务帐号的电子邮件地址。稍后,当您使用该服务账号对 Google Wallet REST API 的请求进行身份验证时,将会用到此内容。
- 点击“完成”按钮。无需完成其他服务账号的创建步骤。
- 点击页面顶部的“键”菜单项。
- 点击“添加密钥”下拉菜单,然后点击“创建新密钥”。
- 选择“JSON”密钥类型。
- 点击“创建”以创建并下载服务帐号密钥。
3. 在 Google 钱包控制台中授权您的服务账号
要使用服务帐号密钥对发送到 Google Wallet REST API 的请求进行身份验证,您必须将服务帐号的电子邮件地址作为用户添加到您的颁发者帐号。如需将服务帐号添加为用户,请执行以下操作:
- 前往 Google Cloud 控制台中的“服务帐号”页面。
- 复制您要用于对 Google Wallet API 请求进行身份验证的服务账号的电子邮件地址。
- 前往 Google Pay & Wallet Console。
- 在左侧导航栏中,点击“用户”。
- 点击“邀请用户”。
- 输入您的服务帐号的电子邮件地址。
- 在“访问权限级别”下拉菜单中,选择“开发者”。
- 点击“邀请”按钮。
添加服务帐号后,您可以使用为其生成的任何服务帐号密钥,对向 Google Wallet REST API 发出的请求进行身份验证。使用服务帐号密钥时,请注意这些凭据是高度敏感的凭据,仅应在安全的服务器端环境中使用。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eGoogle Wallet provides a REST API for programmatic management of passes, enabling server-side integration.\u003c/p\u003e\n"],["\u003cp\u003eTo use the API, you need to enable it in the Google Cloud console, create a Google Cloud service account, and generate a key for authentication.\u003c/p\u003e\n"],["\u003cp\u003eThe service account key is used for signing Pass Objects during creation and authenticating other pass operations like updates and deletions.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, you must authorize your service account by adding its email address as a Developer user in the Google Pay & Wallet console.\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."]]