i don't think the example code has been updated to reflect this new E-Z goodness.
// struct to read the service account secrets file that you downloaded from Google Cloud Console into
type GoogleSecretsConfig struct {
ClientEmail string `json:"client_email"`
ClientId string `json:"client_id"`
ClientSecret string `json:"client_secret"`
RedirectURIs []string `json:"redirect_uris"`
Scope string
AuthURI string `json:"auth_uri"`
TokenURI string `json:"token_uri"`
}
googlesecrets := new(GoogleSecretsConfig)
data, err := ioutil.ReadFile("/tmp/serviceaccountsecretsfilefromCloudConsole.json")
if err != nil {
// do something
}
err = json.Unmarshal(data, &googlesecrets)
if err != nil {
// do something
}
oauthconfig := &oauth.Config{
ClientId: secretsconfig.ClientId,
ClientSecret: secretsconfig.ClientSecret,
AuthURL: secretsconfig.AuthURI,
TokenURL: secretsconfig.TokenURI,
}
// read in the site-specific PEM key file
key, err := ioutil.ReadFile("/tmp/serviceaccountkey.pem")
if err != nil {
// do something
}
// create a basic httpclient that we will use with the json web token assertion
httpclient := &http.Client{}
// encode and send the json web token, getting an *oauth.Token in return
oauthtoken, err := jsonwebtoken.Assert(httpclient)
if err != nil {
// do something
}
// build the oauth http transport
transport := oauth.Transport{Config: oauthconfig}
// set the transport token to be the oauthtoken
transport.Token = oauthtoken
// create the analytics service, passing in the transport
analyticsService, err := analytics.New(transport.Client())
if err != nil {
// do something
}
// create the Analytics Data Service
dataGaService := analytics.NewDataGaService(analyticsService)
hope this helps! let me know if you have any more questions. if you're still having problems, make sure you've explicitly turned on the API specific to the Google service you're trying to authenticate with in the Google Cloud Console for the service account that you're using to authenticate. sounds obvious but ..... :)