1# Google APIs Client Library for Go
2
3## Status
4[![Build Status](https://travis-ci.org/google/google-api-go-client.png)](https://travis-ci.org/google/google-api-go-client)
5
6These are auto-generated Go libraries from the Google Discovery Service's JSON description files of the available "new style" Google APIs.
7
8Due to the auto-generated nature of this collection of libraries, complete APIs or specific versions can appear or go away without notice.
9As a result, you should always locally vendor any API(s) that your code relies upon.
10
11Announcement email:
12
13* http://groups.google.com/group/golang-nuts/browse_thread/thread/6c7281450be9a21e
14
15Getting started documentation:
16
17* https://github.com/google/google-api-go-client/blob/master/GettingStarted.md
18
19In summary:
20
21```
22$ go get google.golang.org/api/storage/v1
23$ go get google.golang.org/api/tasks/v1
24$ go get google.golang.org/api/moderator/v1
25... etc ...
26```
27
28For docs, see e.g.:
29
30* https://godoc.org/google.golang.org/api/storage/v1
31
32The package of a given import is the second-to-last component, before the version number.
33
34For examples, see:
35
36* https://github.com/google/google-api-go-client/tree/master/examples
37
38For support, use the golang-nuts@ mailing list:
39
40* https://groups.google.com/group/golang-nuts
41
42## Application Default Credentials Example
43
44Application Default Credentials provide a simplified way to obtain credentials
45for authenticating with Google APIs.
46
47The Application Default Credentials authenticate as the application itself,
48which make them great for working with Google Cloud APIs like Storage or
49Datastore. They are the recommended form of authentication when building
50applications that run on Google Compute Engine or Google App Engine.
51
52Default credentials are provided by the `golang.org/x/oauth2/google` package. To use them, add the following import:
53
54```
55import "golang.org/x/oauth2/google"
56```
57
58Some 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:
59
60```
61import (
62        "golang.org/x/net/context"
63        "golang.org/x/oauth2/google"
64        "google.golang.org/api/compute/v1"
65)
66
67func main() {
68        // Use oauth2.NoContext if there isn't a good context to pass in.
69        ctx := context.Background()
70
71        client, err := google.DefaultClient(ctx, compute.ComputeScope)
72        if err != nil {
73                //...
74        }
75        computeService, err := compute.New(client)
76        if err != nil {
77                //...
78        }
79}
80```
81
82If you need a `oauth2.TokenSource`, use the `DefaultTokenSource` function:
83
84```
85ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...)
86if err != nil {
87        //...
88}
89client := oauth2.NewClient(ctx, ts)
90```
91
92See also: [golang.org/x/oauth2/google](https://godoc.org/golang.org/x/oauth2/google) package documentation.
93