<html>
<head>
<title>CustomSearchJSONAPIExample</title>
</head>
<body>
<divid="content"></div>
<pid="demo"></p>
<script>
functionhndlr(response){if(response.items==null){document.getElementById("demo").innerHTML+=`<h3> No Results Found </h3>`;}else{for(vari=1;i < response.items.length;i++){varitem=response.items[i];// Make sure HTML in item.htmlTitle is escaped.document.getElementById("content").append(document.createElement("br"),document.createTextNode(item.htmlTitle));}}}</script>
<scriptsrc="https://www.googleapis.com/customsearch/v1?key=YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lecture&callback=hndlr">
</script>
</body>
</html>
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eThe Custom Search JSON API provides a RESTful service for retrieving search results from a Programmable Search Engine using HTTP GET requests.\u003c/p\u003e\n"],["\u003cp\u003eRequests require an API key, Programmable Search Engine ID (cx), and a search query (q) passed as URL parameters.\u003c/p\u003e\n"],["\u003cp\u003eResponse data includes search metadata, search engine information, and an array of search results with URLs, titles, and snippets.\u003c/p\u003e\n"],["\u003cp\u003eDevelopers can integrate the API with JavaScript using the \u003ccode\u003ecallback\u003c/code\u003e parameter for client-side rendering of search results.\u003c/p\u003e\n"],["\u003cp\u003eThe API returns up to the first 100 search results, and the length of the search request should be within 2048 characters.\u003c/p\u003e\n"]]],[],null,["# Use REST to Invoke the API\n\nThis document describes how to use the Custom Search JSON API.\n\nMake a request\n--------------\n\nREST, or [Representational State\nTransfer](http://en.wikipedia.org/wiki/Representational_State_Transfer), in the\nCustom Search JSON API is somewhat different from the usual RESTful APIs. Instead of\nproviding access to resources, the API provides access to a service. As a\nresult, the API provides a single URI that acts as the service endpoint.\n\nYou can retrieve results for a particular search by sending an HTTP `GET`\nrequest to its URI. You pass in the details of the search request as query\nparameters. The format for the Custom Search JSON API URI is: \n\n https://www.googleapis.com/customsearch/v1?[parameters]\n\nThree query `[parameters]` are required with each search request:\n\n- **API key** - Use the `key` query parameter to [identify your\n application](/custom-search/json-api/v1/introduction#identify_your_application_to_google_with_api_key).\n\n - **Programmable Search Engine ID** - Use `cx` to specify the Programmable Search Engine you want to use to perform this search. The search engine must be created with the [Control Panel](https://cse.google.com/all) Note: The Search Engine ID (cx) can be of different format (e.g. 8ac1ab64606d234f1)\n- **Search query** - Use the `q` query parameter to specify your search\n expression.\n\nAll other [query parameters](/custom-search/v1/reference/rest/v1/cse/list) are\noptional.\n\nHere is an example of a request which searches a test Programmable Search Engine\nfor *lectures*: \n\n```\nGET https://www.googleapis.com/customsearch/v1?key=INSERT_YOUR_API_KEY&cx=017576662512468239146:omuauf_lfve&q=lectures\n```\n| **Note:** The limit on the length of the search request should be within 2048 characters.\n\nQuery parameters\n----------------\n\nThere are two types of parameters that you can pass in your request:\n\n- API-specific parameters - define properties of your search, like the search expression, number of results, language etc.\n- Standard query parameters - define technical aspects of your request, like the API key.\n\nAll parameter values need to be URL encoded.\n\n### API-specific query parameters\n\nRequest parameters that apply specifically to the Custom Search JSON API and define your\nsearch request are summarized in the\n[reference](/custom-search/v1/reference/rest/v1/cse/list#request).\n\n### Standard query parameters\n\nQuery parameters that apply to all Custom Search JSON API operations are documented at\n[System Parameters](https://cloud.google.com/apis/docs/system-parameters).\n\nResponse data\n-------------\n\nIf the request succeeds, the server responds with a `200 OK` HTTP status code\nand the response data in JSON format. You can look up the response data\nstructure in the\n[reference](/custom-search/v1/reference/rest/v1/cse/list#response).\n\nThe response data is a JSON object that includes three types of properties:\n\n- Metadata describing the requested search (and, possibly, related search requests)\n- Metadata describing the Programmable Search Engine\n- Search results\n\nFor a detailed description of each property, see the\n[reference](/custom-search/v1/reference/rest/v1/cse/list#response).\n\n### Search request metadata\n\nThe search metadata includes:\n\n- `url` property, which has information about the [OpenSearch template](https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#the-url-element) used for the results returned in this request.\n- `queries` property, which is an array of objects describing the characteristics of possible searches. The name of each object in the array is either the name of an [OpenSearch\n query role](https://github.com/dewitt/opensearch/blob/master/opensearch-1-1-draft-6.md#local-role-values) or one of the two custom roles defined by this API: `previousPage` and `nextPage`. Possible query role objects include:\n - `request`: Metadata describing the query for the current set of results.\n - This role is always present in the response.\n - It is always an array with just one element.\n - `nextPage`: Metadata describing the query to use for the next page of results.\n - This role is not present if the current results are the last page. **Note:**This API returns up to the first 100 results only.\n - When present, it is always a array with just one element.\n - `previousPage`: Metadata describing the query to use for the previous page of results.\n - Not present if the current results are the first page.\n - When present, it is always a array with just one element.\n\n### Search engine metadata\n\nThe `context` property has metadata describing the search engine that performed\nthe search query. It includes the name of the search engine, and any [facet\nobjects](/custom-search/docs/refinements#create) it provides for refining a\nsearch.\n\n### Search results\n\nThe `items` array contains the actual search results. The search results include\nthe URL, title and text snippets that describe the result. In addition, they can\ncontain [rich snippet](/custom-search/docs/snippets) information, if\napplicable.\n\nIf the search results include a `promotions` property, it contains a set of\n[promotions](/custom-search/docs/promotions#sl).\n\nREST from JavaScript\n--------------------\n\nYou can invoke the Custom Search JSON API using REST from JavaScript, using the\n`callback` query parameter and a callback function. This lets you write rich\napplications that display Programmable Search Engine data without writing any\nserver side code.\n\nThe following example uses this approach to display the first page of search\nresults for the query **lecture**: \n\n \u003chtml\u003e\n \u003chead\u003e\n \u003ctitle\u003eCustom Search JSON API Example\u003c/title\u003e\n \u003c/head\u003e\n \u003cbody\u003e\n \u003cdiv id=\"content\"\u003e\u003c/div\u003e\n \u003cp id=\"demo\"\u003e\u003c/p\u003e\n \u003cscript\u003e\n function hndlr(response) {\n if (response.items == null) {\n document.getElementById(\"demo\").innerHTML +=`\u003ch3\u003e No Results Found \u003c/h3\u003e`;\n } else {\n for (var i = 1; i \u003c response.items.length; i++) {\n var item = response.items[i];\n // Make sure HTML in item.htmlTitle is escaped.\n document.getElementById(\"content\").append(\n document.createElement(\"br\"),\n document.createTextNode(item.htmlTitle)\n );\n }\n }\n }\n \u003c/script\u003e\n \u003cscript src=\"https://www.googleapis.com/customsearch/v1?key=YOUR-KEY&cx=017576662512468239146:omuauf_lfve&q=lecture&callback=hndlr\"\u003e\n \u003c/script\u003e\n \u003c/body\u003e\n \u003c/html\u003e\n\n| **Note:** Replace cx with your Search Engine ID. Make sure your Search Engine return results for the query."]]