25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 

40 satır
808 B

  1. // Copyright 2018 Google Inc. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package main
  5. import (
  6. "fmt"
  7. "log"
  8. "net/http"
  9. customsearch "google.golang.org/api/customsearch/v1"
  10. "google.golang.org/api/googleapi/transport"
  11. )
  12. const (
  13. apiKey = "some-api-key"
  14. cx = "some-custom-search-engine-id"
  15. query = "some-custom-query"
  16. )
  17. func customSearchMain() {
  18. client := &http.Client{Transport: &transport.APIKey{Key: apiKey}}
  19. svc, err := customsearch.New(client)
  20. if err != nil {
  21. log.Fatal(err)
  22. }
  23. resp, err := svc.Cse.Siterestrict.List(query).Cx(cx).Do()
  24. if err != nil {
  25. log.Fatal(err)
  26. }
  27. for i, result := range resp.Items {
  28. fmt.Printf("#%d: %s\n", i+1, result.Title)
  29. fmt.Printf("\t%s\n", result.Snippet)
  30. }
  31. }