แนวทางปฏิบัติแนะนำสำหรับ CSS API
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้อธิบายแนวทางปฏิบัติแนะนำบางส่วนเกี่ยวกับการใช้ CSS API
คำแนะนำในหน้านี้ไม่ได้บังคับให้ใช้ API แต่จะช่วยชี้แจง
การใช้งานที่ตั้งใจไว้บางอย่าง
ตั้งค่าสภาพแวดล้อม
หากต้องการตั้งค่าสภาพแวดล้อมในการพัฒนา ให้ทำตามขั้นตอนที่ระบุไว้ในเอกสารประกอบฉบับเริ่มต้น
- สร้างไฟล์ JSON ของผู้ใช้และสิทธิ์ใน Google Cloud Console
- เปิดใช้ CSS API ใน Google Cloud Console
- เพิ่มผู้ใช้ดังกล่าวที่มีสิทธิ์ผู้ดูแลระบบไปยังบัญชี CSS (กลุ่ม CSS หรือโดเมน CSS)
- ตรวจสอบว่าคุณใช้ขอบเขต OAuth ที่ถูกต้อง:
https://www.googleapis.com/auth/content
ตอนนี้ไลบรารีของไคลเอ็นต์อยู่ในที่เก็บมาตรฐานสำหรับภาษาโปรแกรมส่วนใหญ่แล้ว
ดูรายการได้ในหน้าคลังไคลเอ็นต์
ใช้รหัสที่ถูกต้อง
ใช้รหัสที่ถูกต้องกับปลายทาง API ที่ถูกต้อง
- CSS API (
css.googleapis.com
): ใช้รหัสโดเมน CSS เมื่อ
โต้ตอบกับผลิตภัณฑ์ CSS (เช่น
accounts/{cssDomainId}/cssProductInputs:insert
)
- Merchant API (
merchantapi.googleapis.com
): ใช้ Merchant API สำหรับ
ผลิตภัณฑ์ของผู้ขายมาตรฐาน
การสลับข้อมูลเหล่านี้จะทำให้เกิดข้อผิดพลาด ดูรายละเอียดเพิ่มเติมได้ที่ภาพรวมของ CSS API
วิธีที่ดีในการเริ่มต้นใช้งาน
เราขอแนะนำให้ทดสอบด้วยวิธีต่อไปนี้
ListChildAccounts
ListChildAccounts
เป็นการเรียกแบบอ่านอย่างเดียวที่แสดงรายการโดเมน CSS ทั้งหมด (หากเรียกสำหรับ
กลุ่ม CSS) หรือผู้ขาย (หากเรียกสำหรับโดเมน CSS) ดังนั้นจึงเป็น
วิธีที่ดีในการทดสอบว่าได้ตั้งค่าทุกอย่างถูกต้องหรือไม่
แทรก/แสดง/อัปเดต/ลบผลิตภัณฑ์
เมื่อทราบว่า API ทำงานได้แล้ว ให้ลองเพิ่มผลิตภัณฑ์ โปรดใช้raw_provided_id
ที่คุณจำได้
- แทรกผลิตภัณฑ์ทดสอบโดยใช้
InsertCssProductInput
เรามีโค้ดตัวอย่าง
หากคุณต้องการความช่วยเหลือเกี่ยวกับแอตทริบิวต์ที่จะส่ง
- แสดงผลิตภัณฑ์ทั้งหมดโดยใช้
ListCssProducts
อาจมีความล่าช้าในการประมวลผลเล็กน้อยก่อนที่ผลิตภัณฑ์จะปรากฏหลังจากการแทรก
ดังนั้นหากคุณไม่เห็นผลิตภัณฑ์ ให้ลองอีกครั้งหลังจากผ่านไป 2-3 วินาที
- อัปเดตผลิตภัณฑ์รายการเดียวโดยใช้
UpdateCssProductInput
โดยใช้
cssproductinput.name
คุณต้อง
ส่งเฉพาะแอตทริบิวต์ที่ต้องอัปเดต ดูโค้ดตัวอย่าง
ได้ที่นี่
- ลบผลิตภัณฑ์ทดสอบโดยใช้
DeleteCssProductInput
คุณจะต้องใช้
raw_provided_id
CSS API ออกแบบมาสำหรับการเรียกแบบคู่ขนาน คุณจะพบว่าประสิทธิภาพ
ของการดำเนินการเดียวอาจช้า แต่จะเร็วขึ้นมากเมื่อเรียกใช้การดำเนินการเดียวกัน
หลายครั้งแบบขนาน วิธีที่ดีที่สุดในการใช้ฟีเจอร์นี้คือการใช้
ฟังก์ชันการทำงานแบบไม่พร้อมกันของภาษาโปรแกรม
ตัวอย่างจากภาษาโปรแกรมบางภาษา
ค้นหาและใช้ฟังก์ชันการทำงานแบบไม่พร้อมกันของภาษาโปรแกรมเพื่อแทรก
ผลิตภัณฑ์หลายรายการพร้อมกัน คุณไม่ต้องกังวลว่าระบบของเราจะรับภาระหนักเกินไป เพราะเรามีโควต้าไว้สำหรับเรื่องนี้
ดูรายละเอียดเพิ่มเติมได้ในหน้าประสิทธิภาพ
ตรวจสอบความถูกต้องของเพย์โหลด
เพื่อหลีกเลี่ยงข้อผิดพลาดที่พบบ่อย โปรดตรวจสอบว่าเพย์โหลด JSON มีรูปแบบที่ถูกต้อง
- อ่านเอกสารประกอบอย่างเป็นทางการ: โปรดดู
ข้อมูลอ้างอิง CSS API ล่าสุดเสมอเพื่อดู
คำจำกัดความของฟิลด์, Enums, ประเภทข้อมูล และโครงสร้างเพย์โหลด
- ตรวจสอบเพย์โหลดตัวอย่าง: เปรียบเทียบเพย์โหลดกับตัวอย่างโค้ดที่ให้ไว้เพื่อระบุความคลาดเคลื่อน
- ประเภทข้อมูล: ตรวจสอบว่าคุณใช้ประเภทข้อมูลที่ถูกต้อง (เช่น สตริง ออบเจ็กต์ อาร์เรย์) ตามที่ระบุไว้ในเอกสารประกอบ
- ทดสอบทีละน้อย: เริ่มต้นด้วยเพย์โหลดที่ถูกต้องขั้นต่ำเพื่อยืนยันการเชื่อมต่อพื้นฐาน
และค่อยๆ เพิ่มแอตทริบิวต์
อัปเดตผลิตภัณฑ์
เมื่ออัปโหลดผลิตภัณฑ์แล้ว ผลิตภัณฑ์จะอยู่ในระบบของเราจนกว่าจะมีการ
อัปเดต ลบ หรือหมดอายุ
- คุณอัปเดตผลิตภัณฑ์ทั้งหมดได้โดยส่ง
InsertCssProductInput
คำขออีกครั้งraw_provided_id
โดยใช้raw_provided_id
เดียวกันกับที่ใช้ในตอนแรก ในตอนนี้
คุณจะต้องส่งข้อมูลผลิตภัณฑ์ทั้งหมด แม้ว่าจะมีเพียงแอตทริบิวต์บางรายการ
(อาจมีเพียงราคา/ความพร้อมจำหน่ายผลิตภัณฑ์) ที่มีการเปลี่ยนแปลงก็ตาม
- คุณสามารถอัปเดตชิ้นส่วนของผลิตภัณฑ์ได้โดยใช้วิธี PATCH
UpdateCssProductInput
ระบุชื่อผลิตภัณฑ์ และเนื้อหา JSON ที่มี
ข้อมูลที่คุณต้องการอัปเดตสำหรับผลิตภัณฑ์ ซึ่งแตกต่างจาก
InsertCssProductInput
ที่กำหนดให้ต้องระบุช่องที่เกี่ยวข้องทั้งหมดUpdateCssProductInput
โดยคุณจะต้องระบุเฉพาะช่องที่ต้องการเปลี่ยนแปลงเท่านั้น
- คุณลบผลิตภัณฑ์ได้โดยเรียกใช้
DeleteCssProductInput
ด้วย raw_provided_id
เดียวกัน
- ผลิตภัณฑ์จะหมดอายุโดยอัตโนมัติประมาณ 1 เดือนหลังจากการอัปเดตครั้งล่าสุด
โหมดการทำงานต่อเนื่อง
โหมดการทำงานต่อเนื่องอาจมีลักษณะดังนี้
- ใช้รหัสภายในของคุณเองเป็น
raw_provided_id
- อัปโหลดผลิตภัณฑ์ทั้งหมดอีกครั้งตามกำหนดการปกติ อาจเป็นรายสัปดาห์ ซึ่งจะช่วยให้มั่นใจได้ว่า
ผลิตภัณฑ์ที่ใช้งานอยู่จะไม่หมดอายุ
- อัปเดตผลิตภัณฑ์แต่ละรายการทันทีที่ได้รับข้อมูลที่เปลี่ยนแปลงจากผู้ขาย
- หากตอบสนองต่อการเปลี่ยนแปลงได้ไม่ทันที ให้ค้นหาผลิตภัณฑ์ทั้งหมดที่มีการเปลี่ยนแปลง
บ่อยๆ (อาจเป็นทุกชั่วโมง) แล้วอัปโหลดเฉพาะผลิตภัณฑ์เหล่านั้นอีกครั้ง
- สำหรับผลิตภัณฑ์ที่ไม่มีจำหน่ายแล้ว คุณจะใช้
การเรียกใช้การลบหรือตั้งค่าจำนวนข้อเสนอที่พร้อมใช้งานเป็น 0 ก็ได้
- อย่าส่งผลิตภัณฑ์ที่ไม่มีการเปลี่ยนแปลงมาให้เราบ่อยๆ การเรียกเหล่านี้จะนับรวม
ในโควต้า API ของคุณ การรีเฟรชรายสัปดาห์ก็เพียงพอแล้ว
การเลือกข้อเสนอบรรทัดแรก
ข้อเสนอบรรทัดแรกไม่จำเป็นต้องเป็นข้อเสนออันดับต้นๆ หรือข้อเสนอที่ถูกที่สุดในเว็บไซต์ แต่ต้องแสดงอย่างโดดเด่น คุณใช้ตัวเลือกนี้ได้ในกรณีที่ข้อเสนออันดับต้นๆ มีการเปลี่ยนแปลงอย่างรวดเร็ว โดยคุณสามารถเลือกข้อเสนออื่นที่มีความเสถียรมากกว่าได้ที่นี่
โปรดกลับมาตรวจสอบเอกสารนี้เป็นครั้งคราว
เราได้รับความคิดเห็นเกี่ยวกับวิธีปรับปรุง API นี้ และกำลังดำเนินการปรับปรุงบางส่วนให้พร้อมใช้งาน
เราจะอัปเดตหน้านี้เมื่อมี
ฟีเจอร์ใหม่ที่พร้อมให้ใช้งานซึ่งจะช่วยให้การใช้ CSS API ง่ายขึ้น
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-13 UTC
[[["เข้าใจง่าย","easyToUnderstand","thumb-up"],["แก้ปัญหาของฉันได้","solvedMyProblem","thumb-up"],["อื่นๆ","otherUp","thumb-up"]],[["ไม่มีข้อมูลที่ฉันต้องการ","missingTheInformationINeed","thumb-down"],["ซับซ้อนเกินไป/มีหลายขั้นตอนมากเกินไป","tooComplicatedTooManySteps","thumb-down"],["ล้าสมัย","outOfDate","thumb-down"],["ปัญหาเกี่ยวกับการแปล","translationIssue","thumb-down"],["ตัวอย่าง/ปัญหาเกี่ยวกับโค้ด","samplesCodeIssue","thumb-down"],["อื่นๆ","otherDown","thumb-down"]],["อัปเดตล่าสุด 2025-08-13 UTC"],[[["\u003cp\u003eThis document outlines best practices for utilizing the CSS API, including setup, testing methods, performance enhancement, product management, and headline offer selection.\u003c/p\u003e\n"],["\u003cp\u003eOptimize API performance by using asynchronous calls for parallel operations, especially for inserting multiple products simultaneously.\u003c/p\u003e\n"],["\u003cp\u003eMaintain product data by regularly re-uploading all products, updating individual products as needed, and managing product expiration or deletion.\u003c/p\u003e\n"],["\u003cp\u003eThe headline offer can be strategically chosen for prominence and stability, even if it's not the cheapest or top offer on your site.\u003c/p\u003e\n"],["\u003cp\u003eStay informed about API updates and improvements by revisiting this document periodically for new features and simplified usage guidelines.\u003c/p\u003e\n"]]],[],null,["# CSS API Best Practices\n\nThis document describes some of the best practices around using the CSS API. The\nadvice given on this page is not mandatory to use the API, but may help clarify\nsome of the intended use.\n\nSetup up your environment\n-------------------------\n\nTo setup your development environment, follow the steps given from the\n[Quickstart documentation](/comparison-shopping-services/api/guides/quickstart).\n\n- Generate a user and a permissions JSON file on the Google Cloud Console\n- Enable the CSS API in the Google Cloud Console\n- Add that user with Admin permissions to your CSS Account (CSS Group or CSS Domain)\n- Verify you are using the correct OAuth scope: `https://www.googleapis.com/auth/content`\n\nClient libraries are now in the standard repositories for most programming\nlanguage. You can find a list of them on our\n[client library](/comparison-shopping-services/api/client-libraries) page.\n\nUse correct IDs\n---------------\n\nUse the correct IDs with the correct API endpoints:\n\n- **CSS API (`css.googleapis.com`):** Use the **CSS Domain ID** when interacting with CSS products (e.g., `accounts/{cssDomainId}/cssProductInputs:insert`).\n- **Merchant API (`merchantapi.googleapis.com`):** Use the Merchant API for standard merchant products.\n\nMixing these up will lead to errors. Refer to the\n[CSS API Overview](/comparison-shopping-services/api/overview) for more details.\n\nGood methods to get started\n---------------------------\n\nWe recommend testing with the following methods:\n\n### ListChildAccounts\n\n[ListChildAccounts](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.AccountsService.ListChildAccounts)\nis a read-only call that lists all of your CSS Domains (if called for a\nCSS Group) or your Merchants (if called for a CSS Domain). It is therefore a\ngood method to test if everything is setup correctly.\n\n### Insert/List/Update/Delete a product\n\nOnce you know that the API itself works, try adding a product. Make sure you use\na `raw_provided_id` that you remember.\n\n- Insert a test product using [InsertCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.InsertCssProductInput). We have [sample code](/comparison-shopping-services/api/code-samples/cssproducts/insert-css-product-input) if you need help on which attributes to send.\n- List all of your products using [ListCssProducts](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductsService.ListCssProducts). There is a small processing delay before a product shows up after insertion, so if you don't see it, try again after a few seconds.\n- Update a single product using [UpdateCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.UpdateCssProductInput) using your `cssproductinput.name`. You need to send only the attributes required to be updated. Refer to [sample code](/comparison-shopping-services/api/code-samples/cssproducts/update-css-product-input) here.\n- Delete the test product using [DeleteCssProductInput](/comparison-shopping-services/api/reference/rpc/google.shopping.css.v1#google.shopping.css.v1.CssProductInputsService.DeleteCssProductInput). You will need to use the `raw_provided_id`.\n\nUse Async to improve performance\n--------------------------------\n\nThe CSS API is designed for parallel calls. You will find that the performance\nof single operations can be slow, but will be much faster when calling the same\noperation multiple times in parallel. The best way to use this feature is to use\nthe async functionality of your programming language.\n\nExamples from some programming languages:\n\n- For Java, use [insertCssProductInputCallable().futureCall()](https://cloud.google.com/java/docs/reference/google-shopping-css/latest/com.google.shopping.css.v1.CssProductInputsServiceClient#com_google_shopping_css_v1_CssProductInputsServiceClient_insertCssProductInputCallable__)\n- For Python, use [CssProductInputsServiceAsyncClient](https://googleapis.dev/python/google-shopping-css/latest/css_v1/css_product_inputs_service.html)\n- For C#, use [InsertCssProductInputAsync](https://googleapis.dev/dotnet/Google.Shopping.Css.V1/latest/api/Google.Shopping.Css.V1.CssProductInputsService.CssProductInputsServiceClient.html#Google_Shopping_Css_V1_CssProductInputsService_CssProductInputsServiceClient_InsertCssProductInputAsync_Google_Shopping_Css_V1_InsertCssProductInputRequest_Grpc_Core_CallOptions_)\n\nFind and use the Async functionality of your programming language to insert\nmultiple products at the same time. You don't need to worry about overloading\nour systems - this is what the\n[quota limits](/comparison-shopping-services/api/guides/limits) are for.\n\nMore details can be found on our [performance\npage](/comparison-shopping-services/api/guides/performance).\n\nValidate Your Payloads\n----------------------\n\nTo avoid common errors, verify your JSON payloads are correctly formatted:\n\n- **Consult Official Documentation:** Always refer to the latest [CSS API reference](/comparison-shopping-services/api/reference/rest) for field definitions, enums, data types, and payload structure.\n- **Review Sample Payloads:** Compare your payloads with the provided [code samples](/comparison-shopping-services/api/code-samples) to identify discrepancies.\n- **Data Types:** Make sure you are using the correct data types (e.g., strings, objects, arrays) as specified in the documentation.\n- **Test Incrementally:** Start with minimal valid payloads to confirm basic connectivity and gradually add more attributes.\n\nUpdate a product\n----------------\n\nOnce a product is uploaded, it will stay in our system until it is either\nupdated, deleted, or expired.\n\n- You can update the full product by sending the `InsertCssProductInput` request again, using the same `raw_provided_id` you used initially. For now, you will need to send the full product data, even if only some attributes (maybe only price/availablibilty) have changed.\n- You can update parts of a product, using PATCH method `UpdateCssProductInput`, specifying product name,and a JSON body containing the data you would like to update for the product. Unlike `InsertCssProductInput`, that requires all applicable fields to be provided, `UpdateCssProductInput` only requires you to specify the fields you would like to change.\n- You can delete a product by calling `DeleteCssProductInput` with the same `raw_provided_id`.\n- Products expire automatically approximately one month after the last update.\n\nContinuous operation mode\n-------------------------\n\nA continuous operation mode could look like the following:\n\n- Use your own internal IDs as `raw_provided_id`.\n- Re-upload all products on a regular schedule, maybe weekly. This will ensure that active products don't expire.\n- Update individual products as soon as you get the changed data from your merchants.\n - If you can't react to changes immediately, find all changed products frequently (maybe hourly) and re-upload only those products.\n - For products which are no longer available, you can either use the delete call or set the number of available offers to 0.\n - Don't send us unchanged products frequently. These calls would count against your API quota. A weekly refresh is sufficient.\n\nHeadline offer selection\n------------------------\n\nThe headline offer does not necessarily need to be the top offer or the\ncheapest offer on your site, but it does need to be featured prominently. You\ncan use this for cases where your top offer is changing fast: Here you could\nselect another offer which is more stable.\n\nRe-Check this document every once in a while\n--------------------------------------------\n\nWe have received feedback on how to improve this API, and are working on making\nsome of these improvements available. This page will be updated when we have new\nfeatures available that will simplify the usage of the CSS API."]]