Custom Search JSON API: บทนำ
จัดทุกอย่างให้เป็นระเบียบอยู่เสมอด้วยคอลเล็กชัน
บันทึกและจัดหมวดหมู่เนื้อหาตามค่ากำหนดของคุณ
เอกสารนี้จะช่วยให้คุณคุ้นเคยกับ Custom Search JSON API และการใช้งาน
ก่อนจะเริ่ม
สร้าง Programmable Search Engine
เรียกใช้คำขอปัญหาของผู้ใช้ API ต่ออินสแตนซ์ที่มีอยู่ของ Programmable Search Engine
ดังนั้นก่อนใช้ API คุณต้องสร้าง API ในแผงควบคุม ทำตามบทแนะนำ
เพื่อดูข้อมูลเพิ่มเติมเกี่ยวกับตัวเลือกการกำหนดค่าต่างๆ
เมื่อสร้างแล้ว คุณจะเห็นรหัสเครื่องมือค้นหาในส่วนพื้นฐานของหน้าภาพรวม นี่คือพารามิเตอร์ cx
ที่ API ใช้
ระบุแอปพลิเคชันของคุณกับ Google ด้วยคีย์ API
Custom Search JSON API กำหนดให้ใช้คีย์ API คีย์ API เป็นวิธีระบุไคลเอ็นต์ให้ Google ทราบ
หลังจากมีคีย์ API แล้ว แอปพลิเคชันจะเพิ่มพารามิเตอร์การค้นหา key=yourAPIKey
ต่อท้าย URL คำขอทั้งหมดได้ คีย์ API ปลอดภัยสำหรับการฝังใน URL โดยไม่จำเป็นต้องมีการเข้ารหัสใดๆ
ภาพรวม API
การทำงานของ API
การเรียกใน Custom Search JSON API ทำได้เพียงวิธีเดียวคือ
การดำเนินการ |
คำอธิบาย |
การแมป HTTP ของ REST |
list |
แสดงผลการค้นหาที่ขอจาก Programmable Search Engine |
GET |
โมเดลข้อมูล API
ผลลัพธ์ของคำค้นหาสำหรับ Custom Search JSON API คือออบเจ็กต์ JSON ที่มีข้อมูล 3 ประเภทดังนี้
- ข้อมูลเมตาที่อธิบายการค้นหาที่ขอ (และอาจเป็นคำขอการค้นหาที่เกี่ยวข้อง)
- ข้อมูลเมตาที่อธิบาย Programmable Search Engine
- ผลการค้นหา
โปรดดูรายละเอียดเพิ่มเติมในส่วนข้อมูลการตอบกลับในการใช้ REST
โมเดลข้อมูลจะขึ้นอยู่กับข้อกำหนดของ OpenSearch 1.1 นอกจากพร็อพเพอร์ตี้ OpenSearch แบบมาตรฐานแล้ว Custom Search JSON API ยังกำหนดพร็อพเพอร์ตี้ที่กำหนดเอง 2 รายการ และบทบาทการค้นหาที่กำหนดเอง 2 บทบาท ดังนี้
- พร็อพเพอร์ตี้ที่กำหนดเอง
cx
: ตัวระบุของ Programmable Search Engine
safe
: คำอธิบายของระดับฟีเจอร์ค้นหาปลอดภัยเพื่อกรองผลการค้นหาที่แสดง
- บทบาทการค้นหาที่กำหนดเอง
nextPage
: บทบาทที่บ่งบอกว่าสามารถใช้คำค้นหาเพื่อเข้าถึงผลการค้นหาหน้าเชิงตรรกะถัดไปได้ หากมี
previousPage
: บทบาทที่บ่งบอกว่ามีการใช้คำค้นหาเพื่อเข้าถึงหน้าผลลัพธ์แบบตรรกะก่อนหน้า (หากมี)
ลองเลย
หากต้องการลองทดสอบและดูว่า API ทำอะไรได้บ้างโดยไม่ต้องเขียนโค้ด ให้ไปที่เครื่องมือ"ลองใช้ API นี้"
ดูคำอธิบายแบบเต็มของพารามิเตอร์ได้ที่ข้อมูลอ้างอิงของ CSE.list
หากต้องการเรียนรู้วิธีใช้ API ผ่านคำขอ HTTP ให้ไปที่การใช้ REST
เนื้อหาของหน้าเว็บนี้ได้รับอนุญาตภายใต้ใบอนุญาตที่ต้องระบุที่มาของครีเอทีฟคอมมอนส์ 4.0 และตัวอย่างโค้ดได้รับอนุญาตภายใต้ใบอนุญาต Apache 2.0 เว้นแต่จะระบุไว้เป็นอย่างอื่น โปรดดูรายละเอียดที่นโยบายเว็บไซต์ Google Developers Java เป็นเครื่องหมายการค้าจดทะเบียนของ Oracle และ/หรือบริษัทในเครือ
อัปเดตล่าสุด 2025-08-31 UTC
[null,null,["อัปเดตล่าสุด 2025-08-31 UTC"],[[["\u003cp\u003eThis guide introduces the Custom Search JSON API and provides instructions for its use.\u003c/p\u003e\n"],["\u003cp\u003eBefore using the API, you need to create a Programmable Search Engine and obtain an API key.\u003c/p\u003e\n"],["\u003cp\u003eThe API allows you to retrieve search results from your Programmable Search Engine using a single \u003ccode\u003elist\u003c/code\u003e operation.\u003c/p\u003e\n"],["\u003cp\u003eThe API returns results in JSON format containing search metadata, engine details, and the search results themselves.\u003c/p\u003e\n"],["\u003cp\u003eYou can experiment with the API using the provided "Try this API" tool or learn more through detailed documentation and examples.\u003c/p\u003e\n"]]],[],null,["# Custom Search JSON API: Introduction\n\nThis document will help you to get familiar with Custom Search JSON API and its usage.\n\nBefore you start\n----------------\n\n### Create Programmable Search Engine\n\nBy calling the API user issues requests against an existing instance of\nProgrammable Search Engine.\nTherefore, before using the API, you need to create one in the\n[Control Panel](https://programmablesearchengine.google.com/controlpanel/create)\n. Follow the [tutorial](/custom-search/docs/tutorial/creatingcse)\nto learn more about different configuration options.\nOnce it is created, you can find the **Search Engine ID** in the **Overview**\npage's **Basic** section. This is the `cx` parameter used by the API.\n\n### Identify your application to Google with API key\n\nCustom Search JSON API requires the use of an API key. An API key is a way to identify your client to Google.\n\n- [Programmable Search Engine](https://cse.google.com/) (free edition) users: Get a Key\n\nAfter you have an API key, your application can append the query parameter\n`key=yourAPIKey` to all request URLs. The API key is safe for embedding in URLs,\nit doesn't need any encoding.\n\nAPI overview\n------------\n\n### API operations\n\nThere is only one method to invoke in the Custom Search JSON API:\n\n| Operation | Description | REST HTTP mapping |\n|------------------------------------------------------|-------------------------------------------------------------------------|-------------------|\n| [list](/custom-search/v1/reference/rest/v1/cse/list) | Returns the requested search results from a Programmable Search Engine. | `GET` |\n\n### API data model\n\nThe result of a search query to the Custom Search JSON API is a JSON object that includes three types of data:\n\n- Metadata describing the requested search (and, possibly, related search requests)\n- Metadata describing the Programmable Search Engine\n- Search results\n\nSee the Response data section of [Using REST](/custom-search/v1/using_rest#response_data) for more details.\n\nThe data model is based on the OpenSearch 1.1 Specification. In addition to the standard OpenSearch properties, the Custom Search JSON API defines two custom properties and two custom query roles:\n\n- Custom properties\n - `cx`: The identifier of the Programmable Search Engine.\n - `safe`: A description of the safe search level for filtering the returned results.\n- Custom query roles\n - `nextPage`: A role that indicates the query can be used to access the next logical page of results, if any.\n - `previousPage`: A role that indicates the query can be used to access the previous logical page of results, if any.\n\nTry it\n------\n\nTo play around and see what the API can do, without writing any code, visit the\n[\"Try this API\" tool](/custom-search/v1/reference/rest/v1/cse/list?apix=true).\n\nFor a full description of parameters visit the\n[cse.list reference](/custom-search/v1/reference/rest/v1/cse/list).\n\nTo learn how to use the API via HTTP requests, continue to\n[Using REST](/custom-search/v1/using_rest)."]]