您的位置:首页 > 编程语言 > Go语言

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 is 
GET
 and 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 
userip
 parameter (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.
SearcherBase Url
Web Searchhttps://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.
ArgumentExampleDescription
qq=Paris%20HiltonThis argument supplies the query, or search expression, that is passed into the searcher.
vv=1.0This argument supplies protocol version number. The only valid value at this point in time is 
1.0
.
userip?userip=192.168.0.1This 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=4This optional argument supplies the number of results that the application would like to recieve. Values can be any integer between 
1
 and 
8
. Alternately, a value of 
small
 indicates a small result set size or 
4
 results. A value of 
large
 indicates a large result set or 
8
 results. Finally, for filter Custom Search Engines, a value of 
filtered_cse
 will return 
10
 results. If this argument is not supplied, a value of 
small
 is assumed.
hl?hl=frThis 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-Language
 http header. If this header is not present, a value of 
en
 is assumed.
key?key=your-keyThis 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=4This optional argument supplies the start index of the first search result. Each successful response contains a 
cursor
object (see below) which includes an array of 
pages
. The 
start
 property 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=fooThis 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 
callback
 specifies the name of the function called in the response.
callbackFunction(
{"responseData" : {
"results" : [],
"cursor" : {}
},
"responseDetails" : null | string-on-error,
"responseStatus" : 200 | error-code
});

context?context=barThis optional argument is related to the 
context
 argument. When both are supplied, the value of 
context
 alters 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 the 
callback
 and 
context
 arguments 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 
responseData
 property contains a 
results
 array and an optional 
cursor
. These are identical both semantically and structurally to the results returned through the JavaScript Searchers layer. The 
responseStatus
 property contains a value of 
200
 on success and a non-200 http error status code on failure. If there is a failure, 
responseDetails
 contains a diagnostic string.
By using the 
callback
 argument, 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 
callback
 and 
context
 arguments, the response is encoded as a JavaScript procedure call. In this mode of operation, the value of
callback
 becomes the procedure call target, the value of 
context
 is passes as the first argument, the value of 
responseData
 from above is passes as the second argument, the response status is passed as the third argument, and the final argument is either 
null
 or 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:
ArgumentDescription
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

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息