正在生成 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-09-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-10。"],[[["\u003cp\u003eGoogle Wallet's REST API enables programmatic management of passes through HTTP requests, ideal for server-side integrations.\u003c/p\u003e\n"],["\u003cp\u003eTo utilize the API, you must 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 crucial for signing JSON Web Token-encoded Passes Objects during pass creation and authenticating other operations like updates or deletions.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, 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,[]]