I construct the service passing a CredentialsFile and the Scope for auth, then I call the GetDailyMetricsTimeSeries with the right name (locations/{location_id}) but returns error 404.
ctx := context.Background()
performanceService, err := businessprofileperformance.NewService(ctx,
option.WithCredentialsFile("client_secret.json"),
option.WithScopes(Scope))
if err != nil {
log.Println(err.Error())
return
}
cm := performanceService.Locations.GetDailyMetricsTimeSeries("locations/12345...")
cm.DailyMetric("WEBSITE_CLICKS")
cm.DailyRangeStartDateYear(2022)
cm.DailyRangeStartDateMonth(6)
cm.DailyRangeStartDateDay(1)
cm.DailyRangeEndDateYear(2022)
cm.DailyRangeEndDateMonth(12)
cm.DailyRangeEndDateDay(30)
response, err := cm.Do()
if err != nil {
log.Println(err.Error())
return
}
if c := response.HTTPStatusCode; c >= 200 || c <= 299 {
j, _ := response.MarshalJSON()
log.Println(j)
}
my client_secret.json file is like this
{
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "https://accounts.google.com/o/oauth2/auth",
"token_uri": "https://accounts.google.com/o/oauth2/token",
"auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs",
"client_x509_cert_url": ""
}
I think the problem is missing the subject param for the location_id reference, but I didn't found where I can pass it I've hide the personal information of json file
CodePudding user response:
Can you please verify through a get locations call that the GBP location still exists and that you have access to it?
GET https://mybusinessbusinessinformation.googleapis.com/v1/{parent=accounts/*}/locations
404 could indicate that the GBP location was removed.
CodePudding user response:
the problem was in the authentication, the subject was missing, so I managed it this way:
func (a *AppCredential) GetCredentials(ctx context.Context, scope string) (*google.Credentials, error) {
jsonFile, err := os.Open("config/client_secret.json")
if err != nil {
log.Println("error oppening json")
return &google.Credentials{}, err
}
defer jsonFile.Close()
jsonData, _ := ioutil.ReadAll(jsonFile)
creds, err := google.CredentialsFromJSONWithParams(ctx, jsonData, google.CredentialsParams{Scopes: []string{scope}, Subject: "[email protected]"})
if err != nil {
return &google.Credentials{}, err
}
return creds, nil
}
then
ctx := context.Background()
creds, err := appCreds.GetCredentials(ctx, "https://www.googleapis.com/auth/business.manage")
if err != nil {
log.Println(err.Error())
return
}
performanceService, err := businessprofileperformance.NewService(ctx, option.WithCredentials(creds))
if err != nil {
log.Println(err.Error())
return
}
cm := performanceService.Locations.GetDailyMetricsTimeSeries("locations/{location_id}")
response, err := cm.Do()