You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Google Wallet客户端API移除EventTicketClass的HeroImage?

如何通过Google Wallet PHP客户端API移除HeroImage?

针对你遇到的无法移除HeroImage的问题,以下是两种可行的解决方案:

方案1:使用Patch方法(推荐)

问题核心在于:

  • 不能传递空Image对象,必须将heroImage设为null才能触发字段移除
  • 需正确传递updateMask参数(部分库版本可能需要用下划线格式update_mask)

修改后的代码:

$patchClass = new Walletobjects\EventTicketClass();
// 直接赋值null,绕过setHeroImage方法的类型强制检查
$patchClass->heroImage = null;

try {
    return $this->service->eventticketclass->patch(
        "{$this->issuerId}.{$classSuffix}",
        $patchClass,
        ['updateMask' => 'heroImage']
        // 若仍提示参数未知,尝试替换为:['update_mask' => 'heroImage']
    );
} catch (Exception $ex) {
    throw new Exception("An issue occurred while updating your Google Wallet Class: {$classSuffix} ::".$ex->getErrors()[0]['message']);
}

方案2:使用全量Update方法

如果Patch方法仍有参数问题,可以先获取现有Class对象,修改后执行全量更新:

// 获取当前已存在的EventTicketClass
$existingClass = $this->service->eventticketclass->get("{$this->issuerId}.{$classSuffix}");
// 直接将heroImage设为null
$existingClass->heroImage = null;

try {
    return $this->service->eventticketclass->update(
        "{$this->issuerId}.{$classSuffix}",
        $existingClass
    );
} catch (Exception $ex) {
    throw new Exception("An issue occurred while updating your Google Wallet Class: {$classSuffix} ::".$ex->getErrors()[0]['message']);
}

注意事项

  • 不要用new Walletobjects\Image()作为heroImage的值,空Image对象不会触发字段移除逻辑,必须用null
  • 自动生成的Google API模型类的setter方法会强制要求传入Image类型对象,因此直接赋值属性是设置null的有效方式

内容的提问来源于stack exchange,提问作者jmadsen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 22:46:02