购物内容服务
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
通过 Shopping Content 服务,您可以在 Apps 脚本中使用 Google Content API for Shopping。借助此 API,Google Merchant Center 用户可以上传和管理商品详情,以及管理其 Merchant Center 账号。
如需详细了解此服务,请参阅 Google Content API for Shopping 的参考文档。与 Apps 脚本中的所有高级服务一样,Shopping Content Service 使用的对象、方法和参数均与公共 API 相同。
参考
如需详细了解此服务,请参阅 Google Content API for Shopping API 的参考文档。与 Apps 脚本中的所有高级服务一样,高级 Google 表格服务使用的对象、方法和参数均与公共 API 相同。如需了解详情,请参阅方法签名是如何确定的。
如需报告问题并寻求其他支持,请参阅 Google Content API for Shopping 支持指南。
示例代码
下面,我们将展示如何使用购物内容服务的部分功能。
插入商品
此示例演示了如何将单个商品插入到给定的 Merchant Center 账号中。
列出商品
此示例演示了如何针对给定的 Merchant Center 账号列出商品。
批量插入商品
此示例使用 Products.custombatch 同时插入三件商品。
更新账号级税费
此示例代码使用 Accounttax 来更新 Merchant Center 账号的账号级税费信息。如需详细了解账号级税费和运费,请参阅我们的 API 指南。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Shopping Content Service lets you manage Google Merchant Center product listings and accounts within Apps Script using the Google Content API for Shopping.\u003c/p\u003e\n"],["\u003cp\u003eThis is an advanced service that requires enabling before use and mirrors the functionality of the public API.\u003c/p\u003e\n"],["\u003cp\u003eProvided code samples demonstrate common tasks like inserting, listing, and batch-updating products, as well as updating account-level tax information.\u003c/p\u003e\n"],["\u003cp\u003eFor comprehensive details, consult the Google Content API for Shopping reference documentation and support guide linked within the content.\u003c/p\u003e\n"]]],[],null,["# Shopping Content Service\n\nThe Shopping Content Service lets you use the\n[Google Content API for Shopping](/shopping-content) in\nApps Script. This API gives Google Merchant Center users the ability\nto upload and manage their product listings and manage their Merchant\nCenter accounts.\n\nFor detailed information on this service, see the\n[reference documentation](/shopping-content/v2/reference/v2) for the\nGoogle Content API for Shopping. Like all advanced services in Apps Script, the\nShopping Content Service utilizes the same objects, methods, and parameters\nas the public API.\n| **Note:** This is an advanced service that must be [enabled before use](/apps-script/guides/services/advanced).\n\nReference\n---------\n\nFor detailed information on this service, see the\n[reference documentation](/shopping-content/v2/reference/v2) for the\nGoogle Content API for Shopping API. Like all advanced services in Apps Script,\nthe advanced Sheets service uses the same objects, methods, and parameters as\nthe public API. For more information, see [How method signatures are determined](/apps-script/guides/services/advanced#how_method_signatures_are_determined).\n\nTo report issues and find other support, see the\n[Google Content API for Shopping support guide](/shopping-content/support/contact-us).\n\nSample code\n-----------\n\nWe now show how to use a few features of the Shopping Content Service.\n\n### Insert product\n\nThis example demonstrates how to insert a single product into a given\nmerchant center account. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```javascript\n/**\n * Inserts a product into the products list. Logs the API response.\n */\nfunction productInsert() {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n // Create a product resource and insert it\n const productResource = {\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': 'US',\n 'channel': 'online',\n 'availability': 'in stock',\n 'condition': 'new',\n 'googleProductCategory': 'Media \u003e Books',\n 'productType': 'Media \u003e Books',\n 'gtin': '9780007350896',\n 'price': {\n 'value': '2.50',\n 'currency': 'USD'\n },\n 'shipping': [{\n 'country': 'US',\n 'service': 'Standard shipping',\n 'price': {\n 'value': '0.99',\n 'currency': 'USD'\n }\n }],\n 'shippingWeight': {\n 'value': '2',\n 'unit': 'pounds'\n }\n };\n\n try {\n response = ShoppingContent.Products.insert(productResource, merchantId);\n // RESTful insert returns the JSON object as a response.\n console.log(response);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\n### List products\n\nThis example demonstrates how to list your products for a given merchant\ncenter account. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```javascript\n/**\n * Lists the products for a given merchant.\n */\nfunction productList() {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n let pageToken;\n let pageNum = 1;\n const maxResults = 10;\n try {\n do {\n const products = ShoppingContent.Products.list(merchantId, {\n pageToken: pageToken,\n maxResults: maxResults\n });\n console.log('Page ' + pageNum);\n if (products.resources) {\n for (let i = 0; i \u003c products.resources.length; i++) {\n console.log('Item [' + i + '] ==\u003e ' + products.resources[i]);\n }\n } else {\n console.log('No more products in account ' + merchantId);\n }\n pageToken = products.nextPageToken;\n pageNum++;\n } while (pageToken);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\n### Batch insert products\n\nThis example uses\n[Products.custombatch](/shopping-content/v2/reference/v2/products/custombatch)\nto insert three products at the same time. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```javascript\n/**\n * Batch updates products. Logs the response.\n * @param {object} productResource1 The first product resource.\n * @param {object} productResource2 The second product resource.\n * @param {object} productResource3 The third product resource.\n */\nfunction custombatch(productResource1, productResource2, productResource3) {\n const merchantId = 123456; // Replace this with your Merchant Center ID.\n custombatchResource = {\n 'entries': [\n {\n 'batchId': 1,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book124',\n 'product': productResource1\n },\n {\n 'batchId': 2,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book125',\n 'product': productResource2\n },\n {\n 'batchId': 3,\n 'merchantId': merchantId,\n 'method': 'insert',\n 'productId': 'book126',\n 'product': productResource3\n }\n ]\n };\n try {\n const response = ShoppingContent.Products.custombatch(custombatchResource);\n console.log(response);\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```\n\n### Update account-level taxes\n\nThis sample code uses\n[Accounttax](/shopping-content/v2/reference/v2/accounttax) to update the\naccount-level tax information for a Merchant Center account. See our\n[API guide](/shopping-content/v2/how-tos/account-level-tax-shipping) for more\ninformation about account-level tax and shipping. \nadvanced/shoppingContent.gs \n[View on GitHub](https://github.com/googleworkspace/apps-script-samples/blob/main/advanced/shoppingContent.gs) \n\n```javascript\n/**\n * Updates content account tax information.\n * Logs the API response.\n */\nfunction updateAccountTax() {\n // Replace this with your Merchant Center ID.\n const merchantId = 123456;\n\n // Replace this with the account that you are updating taxes for.\n const accountId = 123456;\n\n try {\n const accounttax = ShoppingContent.Accounttax.get(merchantId, accountId);\n console.log(accounttax);\n\n const taxInfo = {\n accountId: accountId,\n rules: [\n {\n 'useGlobalRate': true,\n 'locationId': 21135,\n 'shippingTaxed': true,\n 'country': 'US'\n },\n {\n 'ratePercent': 3,\n 'locationId': 21136,\n 'country': 'US'\n },\n {\n 'ratePercent': 2,\n 'locationId': 21160,\n 'shippingTaxed': true,\n 'country': 'US'\n }\n ]\n };\n\n console.log(ShoppingContent.Accounttax\n .update(taxInfo, merchantId, accountId));\n } catch (e) {\n // TODO (Developer) - Handle exceptions\n console.log('Failed with error: $s', e.error);\n }\n}\n```"]]