目次
ホームページ
バックエンド開発
Golang
GetDailyMetricsTimeSeries の golang gmbapi サービス BusinessProfilePerformance がエラー 404 を返します: 要求されたエンティティが見つかりません



GetDailyMetricsTimeSeries の golang gmbapi サービス BusinessProfilePerformance がエラー 404 を返します: 要求されたエンティティが見つかりません
Feb 06, 2024 am 10:45 AM
lsp
问题内容
我构造了传递 credentialsfile 和身份验证范围的服务,然后使用正确的名称 (locations/{location_id}) 调用 getdailymetricstimeseries,但返回错误 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) }
ログイン後にコピー
我的client_secret.json文件是这样的
ログイン後にコピー
ログイン後にコピー
{ "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": "" }
ログイン後にコピー
我认为问题在于缺少 location_id 引用的主题参数,但我没有找到可以传递它的位置 我已经隐藏了json文件的个人信息
正确答案
问题出在身份验证上,主题丢失了,所以我这样处理:
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 protected]</a>"}) if err != nil { return &google.credentials{}, err } return creds, nil
ログイン後にコピー
}
然后
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()
ログイン後にコピー
以上がGetDailyMetricsTimeSeries の golang gmbapi サービス BusinessProfilePerformance がエラー 404 を返します: 要求されたエンティティが見つかりませんの詳細内容です。詳細については、PHP 中国語 Web サイトの他の関連記事を参照してください。
このウェブサイトの声明
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。

人気の記事
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
1週間前
By 尊渡假赌尊渡假赌尊渡假赌
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌

人気の記事
レポ:チームメイトを復活させる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌
スプリットフィクションを打ち負かすのにどれくらい時間がかかりますか?
3週間前
By DDD
R.E.P.O.説明されたエネルギー結晶と彼らが何をするか(黄色のクリスタル)
1週間前
By 尊渡假赌尊渡假赌尊渡假赌
ハローキティアイランドアドベンチャー:巨大な種を手に入れる方法
3週間前
By 尊渡假赌尊渡假赌尊渡假赌

ホットな記事タグ

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック
Gmailメールのログイン入り口はどこですか?
7288
9


Java チュートリアル
1622
14


CakePHP チュートリアル
1342
46


Laravel チュートリアル
1259
25


PHP チュートリアル
1206
29



Redmi Note13RProでフォントサイズを調整するにはどうすればよいですか?

Redmi Note13RProでダイナミック壁紙を設定するにはどうすればよいですか?

Redmi Note13RProをコンピュータに接続するにはどうすればよいですか?

Redmi Note13RProで写真からテキストを抽出するにはどうすればよいですか?

Redmi Note13RProでフォントサイズを調整するにはどうすればよいですか?
