0

我有一个大型数据集,需要将其推送到 Google Merchant Center 中的帐户级运输设置。我正在通过 PHP 客户端库使用 Google Shopping API。

如果我加载数据的一个子集并在最后调用一次,它工作正常:

$settings = $clientservice->shippingsettings->get('XXXXXX', 'XXXXXX');

for each data point that represents a service
    for each data point that represents a rate group
        create weight/destination state table
    next
next

$settings->setServices($services);
$updatedSettings = $clientservice->shippingsettings->update('XXXXXX', 'XXXXXX', $settings);

但是,如果我加载整个数据集并尝试立即应用它,我会收到 413 Request Too Large 响应。所以我想逐步加载它,一次一项服务。我试过这个:

$settings = $clientservice->shippingsettings->get('XXXXXX', 'XXXXXX');

for each data point that represents a service
    for each data point that represents a rate group
        create weight/destination state table
    next
    $settings->setServices([$service]);
    $updatedSettings = $clientservice->shippingsettings->patch('XXXXXX', 'XXXXXX', $settings);
next

但是,每个服务只是覆盖前一个。据我所知,“补丁”似乎就像“更新”一样运作。任何人都知道如何使这项工作?

4

1 回答 1

1

不是 100% 确定我理解你问题的问题部分。但是我可以告诉您,此更新将更新您随请求发送的所有字段。说我们有一个对象

class Foo { 
    public $aname= 'Jane'; 
    public $aaddress = '12 Blueberry Hill'; 
    public $aage = '23';        

} 

如果我更新

 update('Jane Doe', '12 Blueberry Hill');

它期望在此实例中发送的所有文件 age 可能会设置为 null,因为它没有包含在请求中。

现在补丁只会更新您包含的字段

 update('Jane Doe', '112 Blueberry Hill');

所以这个请求将更新姓名和地址,而不是触及年龄。

如果您遇到大小问题,那么您应该查看您使用的 api 是否包含我认为大多数 Google api 都包含的字段可选参数。然后你可以只请求你想要更新的字段,然后发送一个补丁。

于 2018-06-12T14:11:19.720 回答