rocket
隆重推出
Merchant API - Content API for Shopping 的正式替代方案。
update
获取最新资讯,了解 Merchant API 的新功能、问题修复和更新。
add_alert
注意:Content API for Shopping 将于 2026 年 8 月 18 日停用。
发出请求
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
本指南假设您已全面了解我们的入门指南,并且已设置为发出授权的请求。
设置完所有内容后,您可以向 Google Content API for Shopping 发送请求。以下代码示例演示了如何发送一些简单的请求:
- 创建商品。
- 获取商品列表。
- 从列表中检索特定商品。
- 更新商品的价格。
如需查看完整的方法列表,请参阅
参考文档。
有关详情,请参阅最佳实践页面。此页面介绍了如何最有效地利用 API,
本页还解释了为什么建议发出批处理请求。
如果您在使用 Content API 时遇到问题,请查看
Merchant Center 状态信息中心,了解是否存在服务中断情况,并访问支持页面。
创建产品
您可以在商品 Feed 规范中找到商品可以拥有的所有属性的全部详情。
如需创建商品
,请使用以下代码:
协议
POST /content/v2.1/YOUR_MERCHANT_ID/products
{
"offerId": "book123",
"title": "A Tale of Two Cities",
"description": "A classic novel about the French Revolution",
"link": "http://my-book-shop.com/tale-of-two-cities.html",
"imageLink": "http://my-book-shop.com/tale-of-two-cities.jpg",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "in stock",
"condition": "new",
"googleProductCategory": "Media > Books",
"gtin": "9780007350896",
"price": {
"value": "2.50",
"currency": "GBP"
},
"shipping": [{
"country": "GB",
"service": "Standard shipping",
"price": {
"value": "0.99",
"currency": "GBP"
}
}],
"shippingWeight": {
"value": "200",
"unit": "grams"
}
}
Java
Product product = new Product();
product.setOfferId("book123");
product.setTitle("A Tale of Two Cities");
product.setDescription("A classic novel about the French Revolution");
product.setLink("http://my-book-shop.com/tale-of-two-cities.html");
product.setImageLink("http://my-book-shop.com/tale-of-two-cities.jpg");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
product.setAvailability("in stock");
product.setCondition("new");
product.setGoogleProductCategory("Media > Books");
product.setGtin("9780007350896");
Price price = new Price();
price.setValue("2.50");
price.setCurrency("GBP");
product.setPrice(price);
Price shippingPrice = new Price();
shippingPrice.setValue("0.99");
shippingPrice.setCurrency("GBP");
ProductShipping shipping = new ProductShipping();
shipping.setPrice(shippingPrice);
shipping.setCountry("GB");
shipping.setService("Standard shipping");
ArrayList shippingList = new ArrayList();
shippingList.add(shipping);
product.setShipping(shippingList);
Product result = service.products().insert(merchantId, product).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
$product->setOfferId('book123');
$product->setTitle('A Tale of Two Cities');
$product->setDescription('A classic novel about the French Revolution');
$product->setLink('http://my-book-shop.com/tale-of-two-cities.html');
$product->setImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
$product->setAvailability('in stock');
$product->setCondition('new');
$product->setGoogleProductCategory('Media > Books');
$product->setGtin('9780007350896');
$price = new Google_Service_ShoppingContent_Price();
$price->setValue('2.50');
$price->setCurrency('GBP');
$shipping_price = new Google_Service_ShoppingContent_Price();
$shipping_price->setValue('0.99');
$shipping_price->setCurrency('GBP');
$shipping = new Google_Service_ShoppingContent_ProductShipping();
$shipping->setPrice($shipping_price);
$shipping->setCountry('GB');
$shipping->setService('Standard shipping');
$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();
$shipping_weight->setValue(200);
$shipping_weight->setUnit('grams');
$product->setPrice($price);
$product->setShipping(array($shipping));
$product->setShippingWeight($shipping_weight);
$result = $service->products->insert($merchant_id, $product);
获取商品列表
如需获取商品列表,请使用以下代码:
协议
GET /content/v2.1/YOUR_MERCHANT_ID/products
Java
List productsList = service.products().list(merchantId);
ProductsListResponse page = productsList.execute();
while ((page.getResources() != null) && !page.getResources().isEmpty()) {
for (Product product : page.getResources()) {
System.out.printf("%s %s%n", product.getId(), product.getTitle());
}
if (page.getNextPageToken() == null) {
break;
}
productsList.setPageToken(page.getNextPageToken());
page = productsList.execute();
}
PHP
$products = $service->products->listProducts($merchantId);
$parameters = array();
while (!empty($products->getResources()) {
foreach ($products->getResources() as $product) {
printf("%s %s\n", $product->getId(), $product->getTitle());
}
if (!empty($products->getNextPageToken()) {
break;
}
$parameters['pageToken'] = $products->nextPageToken;
$products = $service->products->listProducts($merchantId, $parameters);
}
检索特定商品
如需从列表中检索特定商品,请使用以下代码:
协议
GET /content/v2.1/YOUR_MERCHANT_ID/products/online:en:GB:book123
Java
Product product = service.products()
.get(merchantId, "online:en:GB:book123")
.execute();
System.out.printf("%s %s\n", product.getId(), product.getTitle());
PHP
$product = $service->products->get($merchant_id, 'online:en:GB:book123');
printf("%s %s\n", $product->getId(), $product->getTitle());
更新线上商品库存状况
您可以使用商品资源中的
补充 Feed 通过以下代码更新线上商品数据:
协议
POST /content/v2.1/YOUR_MERCHANT_ID/products?YOUR_SUPPLEMENTAL_FEED_ID
{
"offerId": "book123",
"contentLanguage": "en",
"targetCountry": "GB",
"feedLabel": "GB",
"channel": "online",
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
// Your unique supplemental feedId
feedId=123456789
Product result = service.products().insert(merchantId, product, feedId).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
// Your unique supplemental feedId
$feedId=123456789
$result = $service->products->insert($merchant_id, $product, $feedId);
更新本地商品库存状况
您可以使用
本地商品目录服务,通过以下代码更新本地商品数据:
协议
POST /content/v2.1/YOUR_MERCHANT_ID/localinventory/online/products/online:en:GB:book123
{
"availability": "out of stock"
}
Java
Product product = new Product();
// Mandatory Fields
product.setOfferId("book123");
product.setContentLanguage("en");
product.setTargetCountry("GB");
product.setChannel("online");
// Optional Fields to Update
product.setAvailability("out of stock");
Product result = service.localinventory().insert(merchantId, product).execute();
PHP
$product = new Google_Service_ShoppingContent_Product();
// Mandatory Fields
$product->setOfferId('book123');
$product->setContentLanguage('en');
$product->setTargetCountry('GB');
$product->setChannel('online');
// Optional Fields to Update
$product->setAvailability('out of stock');
$result = $service->localinventory->insert($merchant_id, $product);
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[null,null,["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe Merchant API is the new version of the Content API for Shopping and represents the future of product data integration with Google.\u003c/p\u003e\n"],["\u003cp\u003eThis guide provides code samples to manage products, including creating, retrieving, listing, and updating them via the API.\u003c/p\u003e\n"],["\u003cp\u003eYou can find comprehensive details on product attributes in the Products Feed Specification and best practices for using the API in the provided links.\u003c/p\u003e\n"],["\u003cp\u003eUtilize supplemental feeds to update online product data and the Local Inventory service to manage local product information efficiently.\u003c/p\u003e\n"],["\u003cp\u003eFor support or to check for service outages, refer to the Merchant Center status dashboard and the Support page.\u003c/p\u003e\n"]]],["The Merchant API beta, a new version of the Content API for Shopping, allows users to manage product data. Key actions include creating a product with details like title, price, and shipping, retrieving a list of products, and fetching a specific product. Additionally, users can update product availability for both online and local inventory using supplemental feeds or the local inventory service. The provided code examples demonstrate these actions in Protocol, Java, and PHP.\n"],null,["# Make requests\n\nThis guide assumes you've worked through\nour [Getting Started](/shopping-content/guides/quickstart) guide and are set up to\nmake authorized requests.\n\nAfter you've set everything up, you can send requests to the Google Content API for Shopping. The following code\nsamples demonstrate how to send a few simple requests:\n\n- Create a product.\n- Get a list of products.\n- Retrieve a specific product from the list.\n- Update a product's price.\n\nFor a full list of methods, see the [reference documentation](/shopping-content/reference/rest/v2.1).\n\nFor more information, see the [Best Practices](/shopping-content/guides/best-practices) page, which\nexplains how to best use the API.\nThis page also explains why batch requests are recommended.\n\n\nIf you're having issues with the Content API, check the [Merchant Center status dashboard](//merchants.google.com/status) for outages, and the\n[Support](/shopping-content/support/contact-us) page.\n\n### Create a product\n\nYou can find full details of all the attributes that a product can have in the\n[Products Feed Specification](//support.google.com/merchants/answer/188494).\nTo [create a product](/shopping-content/reference/rest/v2.1/products/insert), use the following code: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/products\n\n{\n \"offerId\": \"book123\",\n \"title\": \"A Tale of Two Cities\",\n \"description\": \"A classic novel about the French Revolution\",\n \"link\": \"http://my-book-shop.com/tale-of-two-cities.html\",\n \"imageLink\": \"http://my-book-shop.com/tale-of-two-cities.jpg\",\n \"contentLanguage\": \"en\",\n \"targetCountry\": \"GB\",\n \"feedLabel\": \"GB\",\n \"channel\": \"online\",\n \"availability\": \"in stock\",\n \"condition\": \"new\",\n \"googleProductCategory\": \"Media \u003e Books\",\n \"gtin\": \"9780007350896\",\n \"price\": {\n \"value\": \"2.50\",\n \"currency\": \"GBP\"\n },\n \"shipping\": [{\n \"country\": \"GB\",\n \"service\": \"Standard shipping\",\n \"price\": {\n \"value\": \"0.99\",\n \"currency\": \"GBP\"\n }\n }],\n \"shippingWeight\": {\n \"value\": \"200\",\n \"unit\": \"grams\"\n }\n}\n```\n\nJava\n----\n\n```java\nProduct product = new Product();\n\nproduct.setOfferId(\"book123\");\nproduct.setTitle(\"A Tale of Two Cities\");\nproduct.setDescription(\"A classic novel about the French Revolution\");\nproduct.setLink(\"http://my-book-shop.com/tale-of-two-cities.html\");\nproduct.setImageLink(\"http://my-book-shop.com/tale-of-two-cities.jpg\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\nproduct.setAvailability(\"in stock\");\nproduct.setCondition(\"new\");\nproduct.setGoogleProductCategory(\"Media \u003e Books\");\nproduct.setGtin(\"9780007350896\");\n\nPrice price = new Price();\nprice.setValue(\"2.50\");\nprice.setCurrency(\"GBP\");\nproduct.setPrice(price);\n\nPrice shippingPrice = new Price();\nshippingPrice.setValue(\"0.99\");\nshippingPrice.setCurrency(\"GBP\");\n\nProductShipping shipping = new ProductShipping();\nshipping.setPrice(shippingPrice);\nshipping.setCountry(\"GB\");\nshipping.setService(\"Standard shipping\");\n\nArrayList shippingList = new ArrayList();\nshippingList.add(shipping);\nproduct.setShipping(shippingList);\n\nProduct result = service.products().insert(merchantId, product).execute();\n```\n\nPHP\n---\n\n```php\n$product = new Google_Service_ShoppingContent_Product();\n$product-\u003esetOfferId('book123');\n$product-\u003esetTitle('A Tale of Two Cities');\n$product-\u003esetDescription('A classic novel about the French Revolution');\n$product-\u003esetLink('http://my-book-shop.com/tale-of-two-cities.html');\n$product-\u003esetImageLink('http://my-book-shop.com/tale-of-two-cities.jpg');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n$product-\u003esetAvailability('in stock');\n$product-\u003esetCondition('new');\n$product-\u003esetGoogleProductCategory('Media \u003e Books');\n$product-\u003esetGtin('9780007350896');\n\n$price = new Google_Service_ShoppingContent_Price();\n$price-\u003esetValue('2.50');\n$price-\u003esetCurrency('GBP');\n\n$shipping_price = new Google_Service_ShoppingContent_Price();\n$shipping_price-\u003esetValue('0.99');\n$shipping_price-\u003esetCurrency('GBP');\n\n$shipping = new Google_Service_ShoppingContent_ProductShipping();\n$shipping-\u003esetPrice($shipping_price);\n$shipping-\u003esetCountry('GB');\n$shipping-\u003esetService('Standard shipping');\n\n$shipping_weight = new Google_Service_ShoppingContent_ProductShippingWeight();\n$shipping_weight-\u003esetValue(200);\n$shipping_weight-\u003esetUnit('grams');\n\n$product-\u003esetPrice($price);\n$product-\u003esetShipping(array($shipping));\n$product-\u003esetShippingWeight($shipping_weight);\n\n$result = $service-\u003eproducts-\u003einsert($merchant_id, $product);\n```\n\n### Get a list of products\n\nTo [get a list of\nproducts](/shopping-content/reference/rest/v2.1/products/list), use the following code: \n\nProtocol\n--------\n\n```scdoc\nGET /content/v2.1/YOUR_MERCHANT_ID/products\n```\n\nJava\n----\n\n```text\nList productsList = service.products().list(merchantId);\n\nProductsListResponse page = productsList.execute();\nwhile ((page.getResources() != null) && !page.getResources().isEmpty()) {\n for (Product product : page.getResources()) {\n System.out.printf(\"%s %s%n\", product.getId(), product.getTitle());\n }\n\n if (page.getNextPageToken() == null) {\n break;\n }\n\n productsList.setPageToken(page.getNextPageToken());\n page = productsList.execute();\n}\n```\n\nPHP\n---\n\n```ecl\n$products = $service-\u003eproducts-\u003elistProducts($merchantId);\n$parameters = array();\nwhile (!empty($products-\u003egetResources()) {\n foreach ($products-\u003egetResources() as $product) {\n printf(\"%s %s\\n\", $product-\u003egetId(), $product-\u003egetTitle());\n }\n if (!empty($products-\u003egetNextPageToken()) {\n break;\n }\n $parameters['pageToken'] = $products-\u003enextPageToken;\n $products = $service-\u003eproducts-\u003elistProducts($merchantId, $parameters);\n}\n```\n\n### Retrieve a specific product\n\nTo [retrieve a specific\nproduct from the list](/shopping-content/reference/rest/v2.1/products/get), use the following code: \n\nProtocol\n--------\n\n```scdoc\nGET /content/v2.1/YOUR_MERCHANT_ID/products/online:en:GB:book123\n```\n\nJava\n----\n\n```css+lasso\nProduct product = service.products()\n .get(merchantId, \"online:en:GB:book123\")\n .execute();\nSystem.out.printf(\"%s %s\\n\", product.getId(), product.getTitle());\n```\n\nPHP\n---\n\n```css+lasso\n$product = $service-\u003eproducts-\u003eget($merchant_id, 'online:en:GB:book123');\nprintf(\"%s %s\\n\", $product-\u003egetId(), $product-\u003egetTitle());\n```\n\n### Update online product availability\n\nYou can use [Supplemental Feeds](/shopping-content/guides/products/supplemental-feeds) in the Products resource to update online product data with the following\ncode: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/products?YOUR_SUPPLEMENTAL_FEED_ID\n\n{\n \"offerId\": \"book123\",\n \"contentLanguage\": \"en\",\n \"targetCountry\": \"GB\",\n \"feedLabel\": \"GB\",\n \"channel\": \"online\",\n \"availability\": \"out of stock\"\n}\n```\n\nJava\n----\n\n```text\nProduct product = new Product();\n// Mandatory Fields\nproduct.setOfferId(\"book123\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\n\n// Optional Fields to Update\nproduct.setAvailability(\"out of stock\");\n\n// Your unique supplemental feedId\nfeedId=123456789\n\nProduct result = service.products().insert(merchantId, product, feedId).execute();\n```\n\nPHP\n---\n\n```ecl\n$product = new Google_Service_ShoppingContent_Product();\n// Mandatory Fields\n$product-\u003esetOfferId('book123');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n\n// Optional Fields to Update\n$product-\u003esetAvailability('out of stock');\n\n// Your unique supplemental feedId\n$feedId=123456789\n\n$result = $service-\u003eproducts-\u003einsert($merchant_id, $product, $feedId);\n```\n\n### Update local product availability\n\nYou can use the [Local Inventory Service](/shopping-content/reference/rest/v2.1/localinventory) to update local product data with the following code: \n\nProtocol\n--------\n\n```scdoc\nPOST /content/v2.1/YOUR_MERCHANT_ID/localinventory/online/products/online:en:GB:book123\n\n{\n \"availability\": \"out of stock\"\n}\n```\n\nJava\n----\n\n```text\nProduct product = new Product();\n// Mandatory Fields\nproduct.setOfferId(\"book123\");\nproduct.setContentLanguage(\"en\");\nproduct.setTargetCountry(\"GB\");\nproduct.setChannel(\"online\");\n\n// Optional Fields to Update\nproduct.setAvailability(\"out of stock\");\n\nProduct result = service.localinventory().insert(merchantId, product).execute();\n```\n\nPHP\n---\n\n```ecl\n$product = new Google_Service_ShoppingContent_Product();\n// Mandatory Fields\n$product-\u003esetOfferId('book123');\n$product-\u003esetContentLanguage('en');\n$product-\u003esetTargetCountry('GB');\n$product-\u003esetChannel('online');\n\n// Optional Fields to Update\n$product-\u003esetAvailability('out of stock');\n\n$result = $service-\u003elocalinventory-\u003einsert($merchant_id, $product);\n```"]]