examples: Add example of custom search

Fixes #222

Change-Id: I335f268bb1bcad6d649174f9371f4875b7eb07d1
Reviewed-on: https://code-review.googlesource.com/c/35992
Reviewed-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Jean de Klerk <deklerk@google.com>
1 file changed
tree: 71093beb309affe65e9df759c2148887b2be5a2e
  1. .gitignore
  2. .hgtags
  3. AUTHORS
  4. CONTRIBUTING.md
  5. CONTRIBUTORS
  6. GettingStarted.md
  7. LICENSE
  8. NOTES
  9. README.md
  10. TODO
  11. abusiveexperiencereport/
  12. acceleratedmobilepageurl/
  13. accesscontextmanager/
  14. adexchangebuyer/
  15. adexchangebuyer2/
  16. adexchangeseller/
  17. adexperiencereport/
  18. admin/
  19. adsense/
  20. adsensehost/
  21. alertcenter/
  22. analytics/
  23. analyticsreporting/
  24. androiddeviceprovisioning/
  25. androidenterprise/
  26. androidmanagement/
  27. androidpublisher/
  28. api-list.json
  29. appengine/
  30. appsactivity/
  31. appstate/
  32. bigquery/
  33. bigquerydatatransfer/
  34. binaryauthorization/
  35. blogger/
  36. books/
  37. calendar/
  38. chat/
  39. civicinfo/
  40. classroom/
  41. cloudasset/
  42. cloudbilling/
  43. cloudbuild/
  44. clouddebugger/
  45. clouderrorreporting/
  46. cloudfunctions/
  47. cloudiot/
  48. cloudkms/
  49. cloudprofiler/
  50. cloudresourcemanager/
  51. cloudscheduler/
  52. cloudsearch/
  53. cloudshell/
  54. cloudtasks/
  55. cloudtrace/
  56. composer/
  57. compute/
  58. consumersurveys/
  59. container/
  60. content/
  61. customsearch/
  62. dataflow/
  63. dataproc/
  64. datastore/
  65. deploymentmanager/
  66. dfareporting/
  67. dialogflow/
  68. digitalassetlinks/
  69. discovery/
  70. dlp/
  71. dns/
  72. doubleclickbidmanager/
  73. doubleclicksearch/
  74. drive/
  75. driveactivity/
  76. examples/
  77. file/
  78. firebasedynamiclinks/
  79. firebasehosting/
  80. firebaseremoteconfig/
  81. firebaserules/
  82. firestore/
  83. fitness/
  84. fusiontables/
  85. games/
  86. gamesconfiguration/
  87. gamesmanagement/
  88. genomics/
  89. gensupport/
  90. gmail/
  91. google-api-go-generator/
  92. googleapi/
  93. groupsmigration/
  94. groupssettings/
  95. iam/
  96. iamcredentials/
  97. iap/
  98. identitytoolkit/
  99. indexing/
  100. integration-tests/
  101. internal/
  102. iterator/
  103. jobs/
  104. key.json.enc
  105. kgsearch/
  106. language/
  107. lib/
  108. licensing/
  109. logging/
  110. manufacturers/
  111. mirror/
  112. ml/
  113. monitoring/
  114. oauth2/
  115. option/
  116. oslogin/
  117. pagespeedonline/
  118. partners/
  119. people/
  120. photoslibrary/
  121. playcustomapp/
  122. playmoviespartner/
  123. plus/
  124. plusdomains/
  125. poly/
  126. prediction/
  127. proximitybeacon/
  128. pubsub/
  129. qpxexpress/
  130. redis/
  131. replicapool/
  132. replicapoolupdater/
  133. reseller/
  134. runtimeconfig/
  135. safebrowsing/
  136. script/
  137. searchconsole/
  138. servicebroker/
  139. serviceconsumermanagement/
  140. servicecontrol/
  141. servicemanagement/
  142. servicenetworking/
  143. serviceusage/
  144. serviceuser/
  145. sheets/
  146. siteverification/
  147. slides/
  148. sourcerepo/
  149. spanner/
  150. spectrum/
  151. speech/
  152. sqladmin/
  153. storage/
  154. storagetransfer/
  155. streetviewpublish/
  156. support/
  157. surveys/
  158. tagmanager/
  159. tasks/
  160. testing/
  161. texttospeech/
  162. toolresults/
  163. tpu/
  164. tracing/
  165. translate/
  166. transport/
  167. urlshortener/
  168. vault/
  169. videointelligence/
  170. vision/
  171. webfonts/
  172. webmasters/
  173. websecurityscanner/
  174. youtube/
  175. youtubeanalytics/
  176. youtubereporting/
README.md

Google APIs Client Library for Go

Getting Started

$ go get google.golang.org/api/tasks/v1
$ go get google.golang.org/api/moderator/v1
$ go get google.golang.org/api/urlshortener/v1
... etc ...

and using:

package main

import (
	"net/http"

	"google.golang.org/api/urlshortener/v1"
)

func main() {
	svc, err := urlshortener.New(http.DefaultClient)
	// ...
}

Status

GoDoc

These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available “new style” Google APIs.

Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice. As a result, you should always locally vendor any API(s) that your code relies upon.

These client libraries are officially supported by Google. However, the libraries are considered complete and are in maintenance mode. This means that we will address critical bugs and security issues but will not add any new features.

If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub, consider using the Cloud Client Libraries for Go instead. These are the new and idiomatic Go libraries targeted specifically at Google Cloud Platform Services.

The generator itself and the code it produces are beta. Some APIs are alpha/beta, and indicated as such in the import path (e.g., “google.golang.org/api/someapi/v1alpha”).

Application Default Credentials Example

Application Default Credentials provide a simplified way to obtain credentials for authenticating with Google APIs.

The Application Default Credentials authenticate as the application itself, which make them great for working with Google Cloud APIs like Storage or Datastore. They are the recommended form of authentication when building applications that run on Google Compute Engine or Google App Engine.

Default credentials are provided by the golang.org/x/oauth2/google package. To use them, add the following import:

import "golang.org/x/oauth2/google"

Some credentials types require you to specify scopes, and service entry points may not inject them. If you encounter this situation you may need to specify scopes as follows:

import (
        "context"
        "golang.org/x/oauth2/google"
        "google.golang.org/api/compute/v1"
)

func main() {
        // Use oauth2.NoContext if there isn't a good context to pass in.
        ctx := context.Background()

        client, err := google.DefaultClient(ctx, compute.ComputeScope)
        if err != nil {
                //...
        }
        computeService, err := compute.New(client)
        if err != nil {
                //...
        }
}

If you need a oauth2.TokenSource, use the DefaultTokenSource function:

ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...)
if err != nil {
        //...
}
client := oauth2.NewClient(ctx, ts)

See also: golang.org/x/oauth2/google package documentation.