You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.5 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. # Google APIs Client Library for Go
  2. ## Getting Started
  3. ```
  4. $ go get google.golang.org/api/tasks/v1
  5. $ go get google.golang.org/api/moderator/v1
  6. $ go get google.golang.org/api/urlshortener/v1
  7. ... etc ...
  8. ```
  9. and using:
  10. ```go
  11. package main
  12. import (
  13. "net/http"
  14. "google.golang.org/api/urlshortener/v1"
  15. )
  16. func main() {
  17. svc, err := urlshortener.New(http.DefaultClient)
  18. // ...
  19. }
  20. ```
  21. * For a longer tutorial, see the [Getting Started guide](https://github.com/google/google-api-go-client/blob/master/GettingStarted.md).
  22. * For examples, see the [examples directory](https://github.com/google/google-api-go-client/tree/master/examples).
  23. * For support, use the [golang-nuts](https://groups.google.com/group/golang-nuts) mailing list.
  24. * The code review instance may be found [here](https://code-review.googlesource.com).
  25. ## Status
  26. [![GoDoc](https://godoc.org/google.golang.org/api?status.svg)](https://godoc.org/google.golang.org/api)
  27. These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available "new style" Google APIs.
  28. Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice.
  29. As a result, you should always locally vendor any API(s) that your code relies upon.
  30. 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.
  31. If you're working with Google Cloud Platform APIs such as Datastore or Pub/Sub,
  32. consider using the
  33. [Cloud Client Libraries for Go](https://github.com/googleapis/google-cloud-go)
  34. instead. These are the new and
  35. idiomatic Go libraries targeted specifically at Google Cloud Platform Services.
  36. The generator itself and the code it produces are beta. Some APIs are
  37. alpha/beta, and indicated as such in the import path (e.g.,
  38. "google.golang.org/api/someapi/v1alpha").
  39. ## Application Default Credentials Example
  40. Application Default Credentials provide a simplified way to obtain credentials
  41. for authenticating with Google APIs.
  42. The Application Default Credentials authenticate as the application itself,
  43. which make them great for working with Google Cloud APIs like Storage or
  44. Datastore. They are the recommended form of authentication when building
  45. applications that run on Google Compute Engine or Google App Engine.
  46. Default credentials are provided by the `golang.org/x/oauth2/google` package. To use them, add the following import:
  47. ```go
  48. import "golang.org/x/oauth2/google"
  49. ```
  50. 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:
  51. ```go
  52. import (
  53. "context"
  54. "golang.org/x/oauth2/google"
  55. "google.golang.org/api/compute/v1"
  56. )
  57. func main() {
  58. // Use oauth2.NoContext if there isn't a good context to pass in.
  59. ctx := context.Background()
  60. client, err := google.DefaultClient(ctx, compute.ComputeScope)
  61. if err != nil {
  62. //...
  63. }
  64. computeService, err := compute.New(client)
  65. if err != nil {
  66. //...
  67. }
  68. }
  69. ```
  70. If you need a `oauth2.TokenSource`, use the `DefaultTokenSource` function:
  71. ```go
  72. ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...)
  73. if err != nil {
  74. //...
  75. }
  76. client := oauth2.NewClient(ctx, ts)
  77. ```
  78. See also: [golang.org/x/oauth2/google](https://godoc.org/golang.org/x/oauth2/google) package documentation.