Home > Backend Development > Golang > golang gmbapi service BusinessProfilePerformance on GetDailyMetricsTimeSeries returns error 404: Requested entity not found

golang gmbapi service BusinessProfilePerformance on GetDailyMetricsTimeSeries returns error 404: Requested entity not found

WBOY
Release: 2024-02-06 10:45:07
forward
1220 people have browsed it

GetDailyMetricsTimeSeries 上的 golang gmbapi 服务 BusinessProfilePerformance 返回错误 404:未找到请求的实体

Question content

I constructed the service passing the credentialsfile and authentication scope, then called getdailymetricstimeseries with the correct name (locations/{location_id}), but returns error 404.

Copy after login
Copy after login
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)
    }
Copy after login

My client_secret.json file is like this

Copy after login
Copy after login
{
    "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": ""
}
Copy after login

I think the problem is that the topic parameter is missing the location_id reference, but I don't find where I can pass it I have hidden the personal information of the json file


Correct answer


The problem was with the authentication, the topic was missing, so I dealt with it like this:

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: "<a href="https://www.php.cn/link/89fee0513b6668e555959f5dc23238e9" class="__cf_email__" data-cfemail="f796949498829983b7929a969e9bd994989a">[email&#160;protected]</a>"})
if err != nil {
    return &google.credentials{}, err
}
return creds, nil
Copy after login

}

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()
Copy after login

The above is the detailed content of golang gmbapi service BusinessProfilePerformance on GetDailyMetricsTimeSeries returns error 404: Requested entity not found. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
lsp
source:stackoverflow.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template