首先,我的英语不是那么好。我希望你仍然明白我的意思。
我正在尝试使用 google api 2.1 将产品上传到我的提要。但是,在这里,我总是收到一条我无法理解的错误消息。
对https://shoppingcontent.googleapis.com/content/v2.1/{merchantId}/products?feedId=XXX的卷曲请求
链接到文档https://developers.google.com/shopping-content/reference/rest/v2.1/products/insert
public function postRequest($url, $data, $accessToken)
{
$ch = curl_init();
$headers = array(
'Accept: application/json',
'Content-Type: application/json',
"Authorization: $accessToken"
);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_HEADER, 0);
$body = json_encode($data);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Timeout in seconds
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
$data = curl_exec($ch);
$data = json_decode($data);
return $data;
}
$productData = [
"merchantId" => GOOGLE_MERCHANT_ID,
"offerId" => "DE_" . $modelNumber,
"title" => $productName,
"description" => $description,
"link" => $productLink,
"imageLink" => $mainImageLink,
"contentLanguage" => $this->countriesData["DE"]["langIso6391Codes"],
"targetCountry" => $this->countriesData["DE"]["cldrTerritoryCode"],
"channel" => "online",
"adult" => false,
"kind" => "content#product",
"brand" => $manufacturerName,
"googleProductCategory" => $googleCategory,
"gtin" => $productEan,
"mpn" => $modelNumber,
"price" => [
"value" => $productPrice,
"currency" => $this->countriesData["DE"]["currency"]
],
"productWeight" => [
"value" => $productWeight,
"unit" => "kg"
],
"shipping" => [
"price" => [
"value" => $shippingPrice,
"currency" => $this->countriesData["DE"]["currency"]
],
"country" => $this->countriesData["DE"]["cldrTerritoryCode"],
"region" => $this->countriesData["DE"]["region"],
"service" => $shippingTimeName,
],
"productTypes" => ["test"],
"identifierExists" => true,
"source" => "api",
"availability" => "on stock",
"condition" => $this->countriesData["DE"]["productCondition"],
];
在这里,我收到以下错误消息:
object(stdClass)#32 (1) {
["error"]=>
object(stdClass)#31 (4) {
["code"]=>
int(400)
["message"]=>
string(305) "Invalid JSON payload received. Unknown name "price": Cannot find field.
Invalid JSON payload received. Unknown name "productWeight": Cannot find field.
Invalid JSON payload received. Unknown name "shipping": Cannot find field.
Invalid JSON payload received. Unknown name "productTypes": Cannot find field."
["errors"]=>
array(1) {
[0]=>
object(stdClass)#44 (2) {
["message"]=>
string(305) "Invalid JSON payload received. Unknown name "price": Cannot find field.
Invalid JSON payload received. Unknown name "productWeight": Cannot find field.
Invalid JSON payload received. Unknown name "shipping": Cannot find field.
Invalid JSON payload received. Unknown name "productTypes": Cannot find field."
["reason"]=>
string(7) "invalid"
}
}
["status"]=>
string(16) "INVALID_ARGUMENT"
}
}
如果我注释掉被批评的字段:
// "price" => [
// "value" => $productPrice,
// "currency" => $this->countriesData["DE"]["currency"]
// ],
// "productWeight" => [
// "value" => $productWeight,
// "unit" => "kg"
// ],
// "shipping" => [
// "price" => [
// "value" => $shippingPrice,
// "currency" => $this->countriesData["DE"]["currency"]
// ],
// "country" => $this->countriesData["DE"]["cldrTerritoryCode"],
// "region" => $this->countriesData["DE"]["region"],
// "service" => $shippingTimeName,
// ],
// "productTypes" => ["test"],
我收到以下错误消息
object(stdClass)#32 (1) {
["error"]=>
object(stdClass)#31 (3) {
["code"]=>
int(400)
["message"]=>
string(45) "[product] INSERT request must specify product"
["errors"]=>
array(1) {
[0]=>
object(stdClass)#44 (3) {
["message"]=>
string(45) "[product] INSERT request must specify product"
["domain"]=>
string(6) "global"
["reason"]=>
string(8) "required"
}
}
}
}
你们中有人知道我的错误在哪里吗?