使用Google Wallet Web Codelabs示例生成Pass Class遇400错误求助
解决Google Wallet Pass Class创建400错误及有效示例
定位无效参数的实用方法
- 用Google Wallet API Explorer测试:直接在API Explorer中构建请求并发送,它会返回具体的字段错误提示(比如“缺少必填字段issuerName”或“id格式不符合要求”),比单纯的400错误信息更精准。
- 核对必填字段:GenericClass的核心必填项包括:
id:格式必须为[你的Issuer ID].[自定义Class ID],Issuer ID是你在Google Wallet控制台获取的数字IDissuerName:不能为空,需填写你的商户名称classTemplateInfo:必须包含cardTemplateOverride和至少一个行模板配置
- 验证字段格式:
- 颜色值需为6位十六进制格式(如
#4285F4) - 日期需遵循ISO 8601标准(如
2024-10-01) - 枚举值(如
status)必须使用文档规定的大写值(ACTIVE/INACTIVE)
- 颜色值需为6位十六进制格式(如
可直接复用的有效GenericClass请求示例
替换示例中的YOUR_ISSUER_ID为你的实际Issuer ID即可:
{ "id": "YOUR_ISSUER_ID.sample-event-class", "issuerName": "Tech Conference Org", "classTemplateInfo": { "cardTemplateOverride": { "cardBackgroundColor": "#4285F4", "cardRowTemplateInfos": [ { "twoItems": { "startItem": { "firstValue": { "fields": [ { "fieldPath": "object.textModulesData['event-title'].value" } ] } }, "endItem": { "firstValue": { "fields": [ { "fieldPath": "object.textModulesData['event-date'].value" } ] } } } } ] }, "detailsTemplateOverride": { "detailRowTemplateInfos": [ { "labelValueRow": { "label": "Location", "value": { "fields": [ { "fieldPath": "object.textModulesData['event-location'].value" } ] } } } ] } }, "textModulesData": [ { "id": "event-title", "value": "Annual Tech Summit 2024" }, { "id": "event-date", "value": "2024-11-15" }, { "id": "event-location", "value": "San Francisco Convention Center" } ], "status": "ACTIVE" }
常见400错误诱因
id格式错误:未使用Issuer ID.Class ID的结构,或包含特殊字符- 模板配置缺失:
classTemplateInfo中未定义cardTemplateOverride或行模板 - 枚举值大小写错误:比如将
ACTIVE写成小写active - 非法格式值:颜色码不是6位十六进制、日期不符合ISO标准
内容的提问来源于stack exchange,提问作者Zeynep Dayar
相关产品推荐
相关产品推荐

