简体   繁体   English

如何使用PHP在Google Shopping Content API中添加自定义属性?

[英]How to add Custom Attributes in Google shopping content api with php?

I am using google shopping Api from last one year it is working properly. 我从上一年开始使用Google Shopping Api,它工作正常。 But now I want to add new attributes in it such as CustomLabel5 . 但是现在我想在其中添加新属性,例如CustomLabel5 For that I have used setCustomAttributes() method and passed three attributes name , type , value . 为此,我使用了setCustomAttributes()方法并传递了三个属性nametypevalue But it is working showing error 400 invalid attribute values . 但是它正在显示错误400无效的属性值 following is my code please check and suggest proper answer for that. 以下是我的代码,请检查并提出正确的答案。

$product = new Google_Service_ShoppingContent_Product();
$data= new Google_Service_ShoppingContent_ProductCustomAttribute();
$data->setName('CustomLabel5');
$data->setType('text');
$data->setValue('test');
$product->setCustomAttributes($data);

Please give answer. 请给答案。

Fairly simple fix here. 这里的修复很简单。

setCustomAttributes expects an array of Google_Service_ShoppingContent_ProductCustomAttribute instances. setCustomAttributes需要一个Google_Service_ShoppingContent_ProductCustomAttribute实例数组。

What you need is: 您需要的是:

$attributesArray = array($data);
$product->setCustomAttributes($attributesArray);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM