Skip to content

Commit 712b921

Browse files
committed
examples: fix customSearchMain example
Uncommented code and refactored according to the new api. Change-Id: I01c4252e01e8041ed35492c9cd140629258e9653 Reviewed-on: https://code-review.googlesource.com/c/google-api-go-client/+/54551 Reviewed-by: Chris Broadfoot <cbro@google.com>
1 parent 0f6ad06 commit 712b921

1 file changed

Lines changed: 25 additions & 17 deletions

File tree

examples/customsearch.go

Lines changed: 25 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,36 @@
44

55
package main
66

7+
import (
8+
"fmt"
9+
"log"
10+
"net/http"
11+
12+
customsearch "google.golang.org/api/customsearch/v1"
13+
"google.golang.org/api/googleapi/transport"
14+
)
15+
716
const (
817
apiKey = "some-api-key"
918
cx = "some-custom-search-engine-id"
1019
query = "some-custom-query"
1120
)
1221

13-
// TODO(codyoss): uncomment and refactor after generation.
1422
func customSearchMain() {
15-
// client := &http.Client{Transport: &transport.APIKey{Key: apiKey}}
16-
//
17-
// svc, err := customsearch.New(client)
18-
// if err != nil {
19-
// log.Fatal(err)
20-
// }
21-
//
22-
// resp, err := svc.Cse.Siterestrict.List(query).Cx(cx).Do()
23-
// if err != nil {
24-
// log.Fatal(err)
25-
// }
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-
// }
23+
client := &http.Client{Transport: &transport.APIKey{Key: apiKey}}
24+
25+
svc, err := customsearch.New(client)
26+
if err != nil {
27+
log.Fatal(err)
28+
}
29+
30+
resp, err := svc.Cse.List().Q(query).Cx(cx).Do()
31+
if err != nil {
32+
log.Fatal(err)
33+
}
34+
35+
for i, result := range resp.Items {
36+
fmt.Printf("#%d: %s\n", i+1, result.Title)
37+
fmt.Printf("\t%s\n", result.Snippet)
38+
}
3139
}

0 commit comments

Comments
 (0)