如何在Google Content API(购物)中插入customBatch



我正在尝试在谷歌商家中心插入产品。我目前正在使用Google API PHP客户端,我无法在任何类和类扩展中找到toSimpleObject函数。

$this->service = new Google_Service_ShoppingContent($client);
$product = array("batchId" => $batchID,
"merchantId" => $this->googleapi->merchantID,
"method" => "insert",
"product" => array(
"kind" => "content#product",
"offerId" => $skuDetails['SKU'],
"title" => $skuDetails['TITLE'],
"description" => $skuDetails['DESCRIPTION'],
"imageLink" => $skuDetails['IMAGE'],
"contentLanguage" => "en",
"targetCountry" => "US",
"channel" => "online",
"availability" => ($skuDetails['QUANTITY'] > 0)?'in stock':'out of stock',
"brand" => $skuDetails['BRAND'],
"condition" => $skuDetails['CONDITION'],
"minHandlingTime" => $skuDetails['HANDLING_TIME'],
"ageGroup" => 'adult',
"maxHandlingTime" => ($skuDetails['HANDLING_TIME'] + 2),
"googleProductCategory" => (empty($skuDetails['CATEGORYID']))?$skuDetails['CATEGORYPATH']:$skuDetails['CATEGORYID'],
"price" => [
"value" => $price['lp'],
"currency" => "USD"
]
)
);

$productObject = new Google_Service_ShoppingContent_ProductsCustomBatchRequest();
$productObject->setEntries($product);
$result = $this->service->products->custombatch($productObject);

错误:

An uncaught Exception was encountered
Type: Error
Message: Call to undefined method Google_Service_ShoppingContent_ProductsCustomBatchRequest::toSimpleObject()
Line Number: 108
Backtrace:
File: vendor/google/apiclient-services/src/Google/Service/ShoppingContent/Resource/Products.php
Line: 40
Function: call

您应该使用Google_Service_ShoppingContent_Product将数据插入到产品实例中,然后您可以使用自定义批处理上传它

$product = new Google_Service_ShoppingContent_Product();
$product->setId($id);
$product->setTitle($title);

最新更新