Created
November 30, 2015 04:15
-
-
Save ferryzhou/c8e4437ab4367e224be6 to your computer and use it in GitHub Desktop.
google api go client initialize
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://github.com/google/google-api-go-client | |
import ( | |
"golang.org/x/net/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 { | |
//... | |
} | |
} | |
// token | |
ts, err := google.DefaultTokenSource(ctx, scope1, scope2, ...) | |
if err != nil { | |
//... | |
} | |
client := oauth2.NewClient(ctx, ts) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment