1
// Package customsearch provides access to the CustomSearch API.
3
// See https://developers.google.com/custom-search/v1/using_rest
7
// import "google.golang.org/api/customsearch/v1"
9
// customsearchService, err := customsearch.New(oauthHttpClient)
17
"google.golang.org/api/googleapi"
25
// Always reference these packages, just in case the auto-generated code
27
var _ = bytes.NewBuffer
30
var _ = json.NewDecoder
33
var _ = googleapi.Version
35
var _ = strings.Replace
37
const apiId = "customsearch:v1"
38
const apiName = "customsearch"
39
const apiVersion = "v1"
40
const basePath = "https://www.googleapis.com/customsearch/"
42
func New(client *http.Client) (*Service, error) {
44
return nil, errors.New("client is nil")
46
s := &Service{client: client, BasePath: basePath}
47
s.Cse = NewCseService(s)
53
BasePath string // API endpoint base URL
58
func NewCseService(s *Service) *CseService {
59
rs := &CseService{s: s}
63
type CseService struct {
68
Facets [][]*ContextFacetsItem `json:"facets,omitempty"`
70
Title string `json:"title,omitempty"`
73
type ContextFacetsItem struct {
74
Anchor string `json:"anchor,omitempty"`
76
Label string `json:"label,omitempty"`
78
Label_with_op string `json:"label_with_op,omitempty"`
81
type Promotion struct {
82
BodyLines []*PromotionBodyLines `json:"bodyLines,omitempty"`
84
DisplayLink string `json:"displayLink,omitempty"`
86
HtmlTitle string `json:"htmlTitle,omitempty"`
88
Image *PromotionImage `json:"image,omitempty"`
90
Link string `json:"link,omitempty"`
92
Title string `json:"title,omitempty"`
95
type PromotionBodyLines struct {
96
HtmlTitle string `json:"htmlTitle,omitempty"`
98
Link string `json:"link,omitempty"`
100
Title string `json:"title,omitempty"`
102
Url string `json:"url,omitempty"`
105
type PromotionImage struct {
106
Height int64 `json:"height,omitempty"`
108
Source string `json:"source,omitempty"`
110
Width int64 `json:"width,omitempty"`
114
Count int64 `json:"count,omitempty"`
116
Cr string `json:"cr,omitempty"`
118
Cref string `json:"cref,omitempty"`
120
Cx string `json:"cx,omitempty"`
122
DateRestrict string `json:"dateRestrict,omitempty"`
124
DisableCnTwTranslation string `json:"disableCnTwTranslation,omitempty"`
126
ExactTerms string `json:"exactTerms,omitempty"`
128
ExcludeTerms string `json:"excludeTerms,omitempty"`
130
FileType string `json:"fileType,omitempty"`
132
Filter string `json:"filter,omitempty"`
134
Gl string `json:"gl,omitempty"`
136
GoogleHost string `json:"googleHost,omitempty"`
138
HighRange string `json:"highRange,omitempty"`
140
Hl string `json:"hl,omitempty"`
142
Hq string `json:"hq,omitempty"`
144
ImgColorType string `json:"imgColorType,omitempty"`
146
ImgDominantColor string `json:"imgDominantColor,omitempty"`
148
ImgSize string `json:"imgSize,omitempty"`
150
ImgType string `json:"imgType,omitempty"`
152
InputEncoding string `json:"inputEncoding,omitempty"`
154
Language string `json:"language,omitempty"`
156
LinkSite string `json:"linkSite,omitempty"`
158
LowRange string `json:"lowRange,omitempty"`
160
OrTerms string `json:"orTerms,omitempty"`
162
OutputEncoding string `json:"outputEncoding,omitempty"`
164
RelatedSite string `json:"relatedSite,omitempty"`
166
Rights string `json:"rights,omitempty"`
168
Safe string `json:"safe,omitempty"`
170
SearchTerms string `json:"searchTerms,omitempty"`
172
SearchType string `json:"searchType,omitempty"`
174
SiteSearch string `json:"siteSearch,omitempty"`
176
SiteSearchFilter string `json:"siteSearchFilter,omitempty"`
178
Sort string `json:"sort,omitempty"`
180
StartIndex int64 `json:"startIndex,omitempty"`
182
StartPage int64 `json:"startPage,omitempty"`
184
Title string `json:"title,omitempty"`
186
TotalResults int64 `json:"totalResults,omitempty,string"`
190
CacheId string `json:"cacheId,omitempty"`
192
DisplayLink string `json:"displayLink,omitempty"`
194
FileFormat string `json:"fileFormat,omitempty"`
196
FormattedUrl string `json:"formattedUrl,omitempty"`
198
HtmlFormattedUrl string `json:"htmlFormattedUrl,omitempty"`
200
HtmlSnippet string `json:"htmlSnippet,omitempty"`
202
HtmlTitle string `json:"htmlTitle,omitempty"`
204
Image *ResultImage `json:"image,omitempty"`
206
Kind string `json:"kind,omitempty"`
208
Labels []*ResultLabels `json:"labels,omitempty"`
210
Link string `json:"link,omitempty"`
212
Mime string `json:"mime,omitempty"`
214
Pagemap *ResultPagemap `json:"pagemap,omitempty"`
216
Snippet string `json:"snippet,omitempty"`
218
Title string `json:"title,omitempty"`
221
type ResultImage struct {
222
ByteSize int64 `json:"byteSize,omitempty"`
224
ContextLink string `json:"contextLink,omitempty"`
226
Height int64 `json:"height,omitempty"`
228
ThumbnailHeight int64 `json:"thumbnailHeight,omitempty"`
230
ThumbnailLink string `json:"thumbnailLink,omitempty"`
232
ThumbnailWidth int64 `json:"thumbnailWidth,omitempty"`
234
Width int64 `json:"width,omitempty"`
237
type ResultLabels struct {
238
DisplayName string `json:"displayName,omitempty"`
240
Label_with_op string `json:"label_with_op,omitempty"`
242
Name string `json:"name,omitempty"`
245
type ResultPagemap struct {
249
Context *Context `json:"context,omitempty"`
251
Items []*Result `json:"items,omitempty"`
253
Kind string `json:"kind,omitempty"`
255
Promotions []*Promotion `json:"promotions,omitempty"`
257
Queries map[string][]Query `json:"queries,omitempty"`
259
SearchInformation *SearchSearchInformation `json:"searchInformation,omitempty"`
261
Spelling *SearchSpelling `json:"spelling,omitempty"`
263
Url *SearchUrl `json:"url,omitempty"`
266
type SearchSearchInformation struct {
267
FormattedSearchTime string `json:"formattedSearchTime,omitempty"`
269
FormattedTotalResults string `json:"formattedTotalResults,omitempty"`
271
SearchTime float64 `json:"searchTime,omitempty"`
273
TotalResults int64 `json:"totalResults,omitempty,string"`
276
type SearchSpelling struct {
277
CorrectedQuery string `json:"correctedQuery,omitempty"`
279
HtmlCorrectedQuery string `json:"htmlCorrectedQuery,omitempty"`
282
type SearchUrl struct {
283
Template string `json:"template,omitempty"`
285
Type string `json:"type,omitempty"`
288
// method id "search.cse.list":
290
type CseListCall struct {
293
opt_ map[string]interface{}
296
// List: Returns metadata about the search performed, metadata about the
297
// custom search engine used for the search, and the search results.
298
func (r *CseService) List(q string) *CseListCall {
299
c := &CseListCall{s: r.s, opt_: make(map[string]interface{})}
304
// C2coff sets the optional parameter "c2coff": Turns off the
305
// translation between zh-CN and zh-TW.
306
func (c *CseListCall) C2coff(c2coff string) *CseListCall {
307
c.opt_["c2coff"] = c2coff
311
// Cr sets the optional parameter "cr": Country restrict(s).
312
func (c *CseListCall) Cr(cr string) *CseListCall {
317
// Cref sets the optional parameter "cref": The URL of a linked custom
319
func (c *CseListCall) Cref(cref string) *CseListCall {
320
c.opt_["cref"] = cref
324
// Cx sets the optional parameter "cx": The custom search engine ID to
325
// scope this search query
326
func (c *CseListCall) Cx(cx string) *CseListCall {
331
// DateRestrict sets the optional parameter "dateRestrict": Specifies
332
// all search results are from a time period
333
func (c *CseListCall) DateRestrict(dateRestrict string) *CseListCall {
334
c.opt_["dateRestrict"] = dateRestrict
338
// ExactTerms sets the optional parameter "exactTerms": Identifies a
339
// phrase that all documents in the search results must contain
340
func (c *CseListCall) ExactTerms(exactTerms string) *CseListCall {
341
c.opt_["exactTerms"] = exactTerms
345
// ExcludeTerms sets the optional parameter "excludeTerms": Identifies a
346
// word or phrase that should not appear in any documents in the search
348
func (c *CseListCall) ExcludeTerms(excludeTerms string) *CseListCall {
349
c.opt_["excludeTerms"] = excludeTerms
353
// FileType sets the optional parameter "fileType": Returns images of a
354
// specified type. Some of the allowed values are: bmp, gif, png, jpg,
356
func (c *CseListCall) FileType(fileType string) *CseListCall {
357
c.opt_["fileType"] = fileType
361
// Filter sets the optional parameter "filter": Controls turning on or
362
// off the duplicate content filter.
363
func (c *CseListCall) Filter(filter string) *CseListCall {
364
c.opt_["filter"] = filter
368
// Gl sets the optional parameter "gl": Geolocation of end user.
369
func (c *CseListCall) Gl(gl string) *CseListCall {
374
// Googlehost sets the optional parameter "googlehost": The local Google
375
// domain to use to perform the search.
376
func (c *CseListCall) Googlehost(googlehost string) *CseListCall {
377
c.opt_["googlehost"] = googlehost
381
// HighRange sets the optional parameter "highRange": Creates a range in
382
// form as_nlo value..as_nhi value and attempts to append it to query
383
func (c *CseListCall) HighRange(highRange string) *CseListCall {
384
c.opt_["highRange"] = highRange
388
// Hl sets the optional parameter "hl": Sets the user interface
390
func (c *CseListCall) Hl(hl string) *CseListCall {
395
// Hq sets the optional parameter "hq": Appends the extra query terms to
397
func (c *CseListCall) Hq(hq string) *CseListCall {
402
// ImgColorType sets the optional parameter "imgColorType": Returns
403
// black and white, grayscale, or color images: mono, gray, and color.
404
func (c *CseListCall) ImgColorType(imgColorType string) *CseListCall {
405
c.opt_["imgColorType"] = imgColorType
409
// ImgDominantColor sets the optional parameter "imgDominantColor":
410
// Returns images of a specific dominant color: yellow, green, teal,
411
// blue, purple, pink, white, gray, black and brown.
412
func (c *CseListCall) ImgDominantColor(imgDominantColor string) *CseListCall {
413
c.opt_["imgDominantColor"] = imgDominantColor
417
// ImgSize sets the optional parameter "imgSize": Returns images of a
418
// specified size, where size can be one of: icon, small, medium, large,
419
// xlarge, xxlarge, and huge.
420
func (c *CseListCall) ImgSize(imgSize string) *CseListCall {
421
c.opt_["imgSize"] = imgSize
425
// ImgType sets the optional parameter "imgType": Returns images of a
426
// type, which can be one of: clipart, face, lineart, news, and photo.
427
func (c *CseListCall) ImgType(imgType string) *CseListCall {
428
c.opt_["imgType"] = imgType
432
// LinkSite sets the optional parameter "linkSite": Specifies that all
433
// search results should contain a link to a particular URL
434
func (c *CseListCall) LinkSite(linkSite string) *CseListCall {
435
c.opt_["linkSite"] = linkSite
439
// LowRange sets the optional parameter "lowRange": Creates a range in
440
// form as_nlo value..as_nhi value and attempts to append it to query
441
func (c *CseListCall) LowRange(lowRange string) *CseListCall {
442
c.opt_["lowRange"] = lowRange
446
// Lr sets the optional parameter "lr": The language restriction for the
448
func (c *CseListCall) Lr(lr string) *CseListCall {
453
// Num sets the optional parameter "num": Number of search results to
455
func (c *CseListCall) Num(num int64) *CseListCall {
460
// OrTerms sets the optional parameter "orTerms": Provides additional
461
// search terms to check for in a document, where each document in the
462
// search results must contain at least one of the additional search
464
func (c *CseListCall) OrTerms(orTerms string) *CseListCall {
465
c.opt_["orTerms"] = orTerms
469
// RelatedSite sets the optional parameter "relatedSite": Specifies that
470
// all search results should be pages that are related to the specified
472
func (c *CseListCall) RelatedSite(relatedSite string) *CseListCall {
473
c.opt_["relatedSite"] = relatedSite
477
// Rights sets the optional parameter "rights": Filters based on
478
// licensing. Supported values include: cc_publicdomain, cc_attribute,
479
// cc_sharealike, cc_noncommercial, cc_nonderived and combinations of
481
func (c *CseListCall) Rights(rights string) *CseListCall {
482
c.opt_["rights"] = rights
486
// Safe sets the optional parameter "safe": Search safety level
487
func (c *CseListCall) Safe(safe string) *CseListCall {
488
c.opt_["safe"] = safe
492
// SearchType sets the optional parameter "searchType": Specifies the
493
// search type: image.
494
func (c *CseListCall) SearchType(searchType string) *CseListCall {
495
c.opt_["searchType"] = searchType
499
// SiteSearch sets the optional parameter "siteSearch": Specifies all
500
// search results should be pages from a given site
501
func (c *CseListCall) SiteSearch(siteSearch string) *CseListCall {
502
c.opt_["siteSearch"] = siteSearch
506
// SiteSearchFilter sets the optional parameter "siteSearchFilter":
507
// Controls whether to include or exclude results from the site named in
508
// the as_sitesearch parameter
509
func (c *CseListCall) SiteSearchFilter(siteSearchFilter string) *CseListCall {
510
c.opt_["siteSearchFilter"] = siteSearchFilter
514
// Sort sets the optional parameter "sort": The sort expression to apply
516
func (c *CseListCall) Sort(sort string) *CseListCall {
517
c.opt_["sort"] = sort
521
// Start sets the optional parameter "start": The index of the first
523
func (c *CseListCall) Start(start int64) *CseListCall {
524
c.opt_["start"] = start
528
// Fields allows partial responses to be retrieved.
529
// See https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
530
// for more information.
531
func (c *CseListCall) Fields(s ...googleapi.Field) *CseListCall {
532
c.opt_["fields"] = googleapi.CombineFields(s)
536
func (c *CseListCall) Do() (*Search, error) {
537
var body io.Reader = nil
538
params := make(url.Values)
539
params.Set("alt", "json")
540
params.Set("q", fmt.Sprintf("%v", c.q))
541
if v, ok := c.opt_["c2coff"]; ok {
542
params.Set("c2coff", fmt.Sprintf("%v", v))
544
if v, ok := c.opt_["cr"]; ok {
545
params.Set("cr", fmt.Sprintf("%v", v))
547
if v, ok := c.opt_["cref"]; ok {
548
params.Set("cref", fmt.Sprintf("%v", v))
550
if v, ok := c.opt_["cx"]; ok {
551
params.Set("cx", fmt.Sprintf("%v", v))
553
if v, ok := c.opt_["dateRestrict"]; ok {
554
params.Set("dateRestrict", fmt.Sprintf("%v", v))
556
if v, ok := c.opt_["exactTerms"]; ok {
557
params.Set("exactTerms", fmt.Sprintf("%v", v))
559
if v, ok := c.opt_["excludeTerms"]; ok {
560
params.Set("excludeTerms", fmt.Sprintf("%v", v))
562
if v, ok := c.opt_["fileType"]; ok {
563
params.Set("fileType", fmt.Sprintf("%v", v))
565
if v, ok := c.opt_["filter"]; ok {
566
params.Set("filter", fmt.Sprintf("%v", v))
568
if v, ok := c.opt_["gl"]; ok {
569
params.Set("gl", fmt.Sprintf("%v", v))
571
if v, ok := c.opt_["googlehost"]; ok {
572
params.Set("googlehost", fmt.Sprintf("%v", v))
574
if v, ok := c.opt_["highRange"]; ok {
575
params.Set("highRange", fmt.Sprintf("%v", v))
577
if v, ok := c.opt_["hl"]; ok {
578
params.Set("hl", fmt.Sprintf("%v", v))
580
if v, ok := c.opt_["hq"]; ok {
581
params.Set("hq", fmt.Sprintf("%v", v))
583
if v, ok := c.opt_["imgColorType"]; ok {
584
params.Set("imgColorType", fmt.Sprintf("%v", v))
586
if v, ok := c.opt_["imgDominantColor"]; ok {
587
params.Set("imgDominantColor", fmt.Sprintf("%v", v))
589
if v, ok := c.opt_["imgSize"]; ok {
590
params.Set("imgSize", fmt.Sprintf("%v", v))
592
if v, ok := c.opt_["imgType"]; ok {
593
params.Set("imgType", fmt.Sprintf("%v", v))
595
if v, ok := c.opt_["linkSite"]; ok {
596
params.Set("linkSite", fmt.Sprintf("%v", v))
598
if v, ok := c.opt_["lowRange"]; ok {
599
params.Set("lowRange", fmt.Sprintf("%v", v))
601
if v, ok := c.opt_["lr"]; ok {
602
params.Set("lr", fmt.Sprintf("%v", v))
604
if v, ok := c.opt_["num"]; ok {
605
params.Set("num", fmt.Sprintf("%v", v))
607
if v, ok := c.opt_["orTerms"]; ok {
608
params.Set("orTerms", fmt.Sprintf("%v", v))
610
if v, ok := c.opt_["relatedSite"]; ok {
611
params.Set("relatedSite", fmt.Sprintf("%v", v))
613
if v, ok := c.opt_["rights"]; ok {
614
params.Set("rights", fmt.Sprintf("%v", v))
616
if v, ok := c.opt_["safe"]; ok {
617
params.Set("safe", fmt.Sprintf("%v", v))
619
if v, ok := c.opt_["searchType"]; ok {
620
params.Set("searchType", fmt.Sprintf("%v", v))
622
if v, ok := c.opt_["siteSearch"]; ok {
623
params.Set("siteSearch", fmt.Sprintf("%v", v))
625
if v, ok := c.opt_["siteSearchFilter"]; ok {
626
params.Set("siteSearchFilter", fmt.Sprintf("%v", v))
628
if v, ok := c.opt_["sort"]; ok {
629
params.Set("sort", fmt.Sprintf("%v", v))
631
if v, ok := c.opt_["start"]; ok {
632
params.Set("start", fmt.Sprintf("%v", v))
634
if v, ok := c.opt_["fields"]; ok {
635
params.Set("fields", fmt.Sprintf("%v", v))
637
urls := googleapi.ResolveRelative(c.s.BasePath, "v1")
638
urls += "?" + params.Encode()
639
req, _ := http.NewRequest("GET", urls, body)
640
googleapi.SetOpaque(req.URL)
641
req.Header.Set("User-Agent", "google-api-go-client/0.5")
642
res, err := c.s.client.Do(req)
646
defer googleapi.CloseBody(res)
647
if err := googleapi.CheckResponse(res); err != nil {
651
if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
656
// "description": "Returns metadata about the search performed, metadata about the custom search engine used for the search, and the search results.",
657
// "httpMethod": "GET",
658
// "id": "search.cse.list",
659
// "parameterOrder": [
664
// "description": "Turns off the translation between zh-CN and zh-TW.",
665
// "location": "query",
669
// "description": "Country restrict(s).",
670
// "location": "query",
674
// "description": "The URL of a linked custom search engine",
675
// "location": "query",
679
// "description": "The custom search engine ID to scope this search query",
680
// "location": "query",
684
// "description": "Specifies all search results are from a time period",
685
// "location": "query",
689
// "description": "Identifies a phrase that all documents in the search results must contain",
690
// "location": "query",
694
// "description": "Identifies a word or phrase that should not appear in any documents in the search results",
695
// "location": "query",
699
// "description": "Returns images of a specified type. Some of the allowed values are: bmp, gif, png, jpg, svg, pdf, ...",
700
// "location": "query",
704
// "description": "Controls turning on or off the duplicate content filter.",
709
// "enumDescriptions": [
710
// "Turns off duplicate content filter.",
711
// "Turns on duplicate content filter."
713
// "location": "query",
717
// "description": "Geolocation of end user.",
718
// "location": "query",
722
// "description": "The local Google domain to use to perform the search.",
723
// "location": "query",
727
// "description": "Creates a range in form as_nlo value..as_nhi value and attempts to append it to query",
728
// "location": "query",
732
// "description": "Sets the user interface language.",
733
// "location": "query",
737
// "description": "Appends the extra query terms to the query.",
738
// "location": "query",
742
// "description": "Returns black and white, grayscale, or color images: mono, gray, and color.",
748
// "enumDescriptions": [
753
// "location": "query",
756
// "imgDominantColor": {
757
// "description": "Returns images of a specific dominant color: yellow, green, teal, blue, purple, pink, white, gray, black and brown.",
770
// "enumDescriptions": [
782
// "location": "query",
786
// "description": "Returns images of a specified size, where size can be one of: icon, small, medium, large, xlarge, xxlarge, and huge.",
796
// "enumDescriptions": [
805
// "location": "query",
809
// "description": "Returns images of a type, which can be one of: clipart, face, lineart, news, and photo.",
817
// "enumDescriptions": [
824
// "location": "query",
828
// "description": "Specifies that all search results should contain a link to a particular URL",
829
// "location": "query",
833
// "description": "Creates a range in form as_nlo value..as_nhi value and attempts to append it to query",
834
// "location": "query",
838
// "description": "The language restriction for the search results",
876
// "enumDescriptions": [
910
// "Chinese (Simplified)",
911
// "Chinese (Traditional)"
913
// "location": "query",
918
// "description": "Number of search results to return",
919
// "format": "uint32",
920
// "location": "query",
924
// "description": "Provides additional search terms to check for in a document, where each document in the search results must contain at least one of the additional search terms",
925
// "location": "query",
929
// "description": "Query",
930
// "location": "query",
935
// "description": "Specifies that all search results should be pages that are related to the specified URL",
936
// "location": "query",
940
// "description": "Filters based on licensing. Supported values include: cc_publicdomain, cc_attribute, cc_sharealike, cc_noncommercial, cc_nonderived and combinations of these.",
941
// "location": "query",
946
// "description": "Search safety level",
952
// "enumDescriptions": [
953
// "Enables highest level of safe search filtering.",
954
// "Enables moderate safe search filtering.",
955
// "Disables safe search filtering."
957
// "location": "query",
961
// "description": "Specifies the search type: image.",
965
// "enumDescriptions": [
966
// "custom image search"
968
// "location": "query",
972
// "description": "Specifies all search results should be pages from a given site",
973
// "location": "query",
976
// "siteSearchFilter": {
977
// "description": "Controls whether to include or exclude results from the site named in the as_sitesearch parameter",
982
// "enumDescriptions": [
986
// "location": "query",
990
// "description": "The sort expression to apply to the results",
991
// "location": "query",
995
// "description": "The index of the first result to return",
996
// "format": "uint32",
997
// "location": "query",