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

Php 如何在Google Content API中插入customBatch(购物),php,google-api-php-client,google-shopping-api,Php,Google Api Php Client,Google Shopping Api,我试图在谷歌商务中心插入产品。我目前正在使用GoogleAPI PHP客户端,在任何类和扩展它的类中都找不到toSimpleObject函数 $this->service = new Google_Service_ShoppingContent($client); $product = array("batchId" => $batchID, "merchantId" => $this->googleapi->merch

我试图在谷歌商务中心插入产品。我目前正在使用GoogleAPI 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\u Service\u ShoppingContent\u Product
将数据插入产品实例,然后您可以使用custombatch上传数据

 $product = new Google_Service_ShoppingContent_Product();

 $product->setId($id);
 $product->setTitle($title);

在我的例子中,这个问题是因为我使用的类名与GoogleAPI(供应商)和项目文件中的类名相同(我在其中调用API)。产生错误的类名是“Google_模型”。我已经修改了它,并且知道它可以正常工作:-)如果您需要批量插入产品,这将不起作用。我的问题与批量上传有关