google 本地搜索参数设置
2011-05-09 16:07
169 查看
Flash and other Non-Javascript Environments
For Flash developers, and those developers that have a need to access the Search API from other Non-Javascript environments, the API exposes a simple RESTful interface. In all cases, the method supported isGETand the response format is a JSON encoded result set with embedded status codes. Applications that use this interface must abide by all existing terms of service. An area to pay special attention to relates to correctly identifying yourself in your requests. Applications MUST always include a valid and accurate http referer header in their requests. In addition, we ask, but do not require, that each request contains a valid API Key. By providing a key, your application provides us with a secondary identification mechanism that is useful should we need to contact you in order to correct any problems. Read more about the usefulness of having an API key
Developers are also encouraged to make use of the
useripparameter (see below) to supply the IP address of the end-user on whose behalf you are making the API request. Doing so will help distinguish this legitimate server-side traffic from traffic which doesn't come from an end-user.
Like the core Javascript interface, this interface is exposed through a uniform URL containing a mix of both standard and searcher specific CGI arguments. Your application can use an http stack of it's choosing. The only requirements are that you must be able to construct a properly constructed URL with all necessary CGI arguments, that you send an http referer header that accurately identifies your application, and that you are able to process the JSON encoded response.
Standard URL Base Address'
Each search endpoint is accessed through a standard URL. The following table lists the URL used to access each service.Searcher | Base Url |
---|---|
Web Search | https://ajax.googleapis.com/ajax/services/search/web |
Standard URL Arguments
Each request contains a mix of standard URL arguments and an optional set of searcher specific arguments. This section describes the standard arguments that are uniform across all searchers and that convey virtually identical semantic information to each searcher. In some cases, an argument is optional. This is indicated with a?following the name of the argument. In all cases, the value of a CGI argument must be properly escaped (e.g., via the functional equivalent of Javascript's
encodeURIComponent()method).
The following table lists the standard URL arguments. Additional sections appear below that highlight searcher specific arguments.
Argument | Example | Description |
---|---|---|
q | q=Paris%20Hilton | This argument supplies the query, or search expression, that is passed into the searcher. |
v | v=1.0 | This argument supplies protocol version number. The only valid value at this point in time is 1.0. |
userip? | userip=192.168.0.1 | This argument supplies the IP address of the end-user on whose behalf the request is being made. Requests that include it are less likely to be mistaken for abuse. In choosing to utilize this parameter, please be sure that you're in compliance with any local laws, including any laws relating to disclosure of personal information being sent. |
rsz? | rsz=4 | This optional argument supplies the number of results that the application would like to recieve. Values can be any integer between 1and 8. Alternately, a value of smallindicates a small result set size or 4results. A value of largeindicates a large result set or 8results. Finally, for filter Custom Search Engines, a value of filtered_csewill return 10results. If this argument is not supplied, a value of smallis assumed. |
hl? | hl=fr | This optional argument supplies the host language of the application making the request. If this argument is not present then the system will choose a value based on the value of the Accept-Languagehttp header. If this header is not present, a value of enis assumed. |
key? | key=your-key | This optional argument supplies the application's key. If specified, it must be a valid key associated with your site which is validated against the passed referer header. The advantage of supplying a key is so that we can identify and contact you should something go wrong with your application. Without a key, we will still take the same appropriate measures on our side, but we will not be able to contact you. It is definitely best for you to pass a key. |
start? | start=4 | This optional argument supplies the start index of the first search result. Each successful response contains a cursorobject (see below) which includes an array of pages. The startproperty for a page may be used as a valid value for this argument. For reference, a sample cursor object is shown below: "cursor": { "pages": [ { "start": "0", "label": 1 }, { "start": "4", "label": 2 }, { "start": "8", "label": 3 }, { "start": "12","label": 4 } ], "estimatedResultCount": "48758", "currentPageIndex": 0, "moreResultsUrl": "http://www.google.com/search..." } |
callback? | callback=foo | This optional argument alters the standard response format. When supplied, instead of producing a simple JSON encoded object, the system produces a Javascript function call response where the value of callbackspecifies the name of the function called in the response. callbackFunction( {"responseData" : { "results" : [], "cursor" : {} }, "responseDetails" : null | string-on-error, "responseStatus" : 200 | error-code }); |
context? | context=bar | This optional argument is related to the contextargument. When both are supplied, the value of contextalters the normal response format associated with callback. The new format is: callbackFunction( contextValue, // the context arg value responseObject, // the collection of results and cursor responseStatus, // 200 on success, non-200 on failure errorDetails) // error string for non-200 response |
Standard Response Format
As discussed briefly in the previous section, there are two major variations in the response format. When thecallbackand
contextarguments are not supplied, the response format is a simple JSON object:
{ "responseData" : { "results" : [], "cursor" : {} }, "responseDetails" : null | string-on-error, "responseStatus" : 200 | error-code }
In the JSON fragment above, note that the
responseDataproperty contains a
resultsarray and an optional
cursor. These are identical both semantically and structurally to the results returned through the JavaScript Searchers layer. The
responseStatusproperty contains a value of
200on success and a non-200 http error status code on failure. If there is a failure,
responseDetailscontains a diagnostic string.
By using the
callbackargument, applications can easily request a JavaScript callback::
callback({ "responseData" : { "results" : [], "cursor" : {} }, "responseDetails" : null | string-on-error, "responseStatus" : 200 | error-code });
If the application supplies both
callbackand
contextarguments, the response is encoded as a JavaScript procedure call. In this mode of operation, the value of
callbackbecomes the procedure call target, the value of
contextis passes as the first argument, the value of
responseDatafrom above is passes as the second argument, the response status is passed as the third argument, and the final argument is either
nullor a diagnostic string.
foo('bar',{ "results": [ { "GsearchResultClass": "GwebSearch", "unescapedUrl": "http://en.wikipedia.org/wiki/Paris_Hilton", "url": "http://en.wikipedia.org/wiki/Paris_Hilton", "visibleUrl": "en.wikipedia.org", "cacheUrl": "http://www.google.com/search?q/u003dcache:TwrPfhd22hYJ:en.wikipedia.org", "title": "/u003cb/u003eParis Hilton/u003c/b/u003e - Wikipedia, the free encyclopedia", "titleNoFormatting": "Paris Hilton - Wikipedia, the free encyclopedia", "content": "In 2006, she released her debut album /u003cb/u003eParis/u003c/b/u003e..." }, { "GsearchResultClass": "GwebSearch", "unescapedUrl": "http://www.imdb.com/name/nm0385296/", "url": "http://www.imdb.com/name/nm0385296/", "visibleUrl": "www.imdb.com", "cacheUrl": "http://www.google.com/search?q/u003dcache:1i34KkqnsooJ:www.imdb.com", "title": "/u003cb/u003eParis Hilton/u003c/b/u003e", "titleNoFormatting": "Paris Hilton", "content": "Self: Zoolander. Socialite /u003cb/u003eParis Hilton/u003c/b/u003e was..." }, ... ], "cursor": { "pages": [ { "start": "0", "label": 1 }, { "start": "4", "label": 2 }, { "start": "8", "label": 3 }, { "start": "12","label": 4 } ], "estimatedResultCount": "59600000", "currentPageIndex": 0, "moreResultsUrl": "http://www.google.com/search?oe/u003dutf8..." } } , 200, null)
Web Search Specific Arguments
The Web Search system supports a number of optional arguments which are all listed below:Argument | Description |
---|---|
cx? | This optional argument supplies the unique id for the Custom Search Engine that should be used for this request (e.g.,cx=000455696194071821846:reviews). |
cref? | This optional argument supplies the url of a linked Custom Search Engine specification that should be used to satisfy this request (e.g.,cref=http%3A%2F%2Fwww.google.com%2Fcse%2Fsamples%2Fvegetarian.xml). |
safe? | This optional argument supplies the search safety level which may be one of:safe=active- enables the highest level of safe search filtering safe=moderate- enables moderate safe search filtering (default) safe=off- disables safe search filtering |
lr? | This optional argument allows the caller to restrict the search to documents written in a particular language (e.g., lr=lang_ja). This list contains the permissible set of values. |
filter?New! | This optional argument controls turning on or off the duplicate content filter:filter=0- Turns off the duplicate content filter filter=1- Turns on the duplicate content filter (default) |
gl? New! | This optional argument allows the caller to tailor the results to a specific country. The value should be a valid country code (e.g. uk, de, etc.). If this argument is not present, then the system will use a value based on the domain used to load the API (e.g. https://www.google.com/jsapi). If the API loader was not used, a value of "us" is assumed. |
Searcher and Drawing Options
相关文章推荐
- 世界之窗浏览器设置google搜索
- 设置Chrome默认搜索为Google.com
- 常用google搜索参数
- 针式PKM帮助五:Google和百度桌面搜索集成的有关设置和使用技巧
- 设置firefox的默认google搜索.com而不是.hk
- 设置google搜索在新标签中打开
- 设置 Chrome 点击 Google 搜索结果在新的页面打开
- chrome加载本地其他文件启动参数设置
- Google开源rlz库,用户可读懂谷歌搜索中的rlz参数
- google搜索url参数总结
- baidu、Google、Yahoo搜索引擎搜索代码参数
- Google推出语音本地搜索 与微软展开竞争
- 写一段程序,查看本地JVM参数设置
- Google Chrome设置地址栏默认为Google搜索
- [android M]搜索参数的设置
- chrome与google搜索设置
- google搜索栏设置
- 怎么把Chrome的默认搜索设置成google.com?
- 谈谈google sitemap网站地图工具参数设置
- 百度、Google 的搜索参数