


我构造了传递 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 サイトの他の関連記事を参照してください。

goisidealforbuildingscalablessystemsduetoitssimplicity、効率性、およびビルド・インコンカレンシsupport.1)

intionSingOrunautomaticallyは()andareuseforstingupenments andinitializingvariables.usemforsimpletasks、回避効果を回避し、測定可能性を測定することを検討します。

goinitializeSpackages intheordertheyareimport extionsitions withinitionsiteintheirdefinition ordord、およびfilenamesdetermineTheOordCrossMultiplefiles.thisprocesccanbeandeanded by -dependenciessedieSiesは、このマイレアドカンフレシニティン化の対象となります

custominterfacesingoarecrucialforwritingfficable、maintable、andtatablecode.theyeNabledeveloveerStofofofovioroverimplementation、拡張、methodsodsignaturesthattypespessmustimment、interfaceforoderueusavelya

シミュレーションとテストにインターフェイスを使用する理由は、インターフェイスにより、実装を指定せずに契約の定義を可能にし、テストをより孤立し、メンテナンスしやすくするためです。 1)インターフェイスの暗黙的な実装により、モックオブジェクトを簡単に作成できます。これにより、テストの実際の実装を置き換えることができます。 2)インターフェイスを使用すると、ユニットテストでのサービスの実際の実装を簡単に置き換えることができ、テストの複雑さと時間を短縮できます。 3)インターフェイスによって提供される柔軟性により、さまざまなテストケースのシミュレートされた動作の変更が可能になります。 4)インターフェイスは、テスト可能なコードを最初から設計し、コードのモジュール性と保守性を向上させるのに役立ちます。

Goでは、init関数はパッケージの初期化に使用されます。 1)init関数は、パッケージの初期化時に自動的に呼び出され、グローバル変数の初期化、接続の設定、構成ファイルの読み込みに適しています。 2)ファイルの順序で実行できる複数のinit関数がある場合があります。 3)それを使用する場合、実行順序、テストの難易度、パフォーマンスへの影響を考慮する必要があります。 4)副作用を減らし、依存関係の注入を使用し、初期化を遅延させることをお勧めします。

go'sselectStatementStreamLinesConcurrentProgrambyMultipLexIngoperations.1)Itallow swaitingonMultipleChanneloperations、実行、exectingThefirstreadyone.2)

コンテキストアンドウェイトグループは、フォーマネングに焦点を合わせており、contextAllowsingSignalingCancellationAndDeadlinesAcrossapiboundariesを採用し、GoroutinesscanSclacefly.2)WaitGroupssynchronizeGoroutines、Allcompletebebroproproproproproproprotinesを保証します


ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

Video Face Swap
完全無料の AI 顔交換ツールを使用して、あらゆるビデオの顔を簡単に交換できます。

人気の記事

ホットツール

SublimeText3 英語版
推奨: Win バージョン、コードプロンプトをサポート!

ZendStudio 13.5.1 Mac
強力な PHP 統合開発環境

MinGW - Minimalist GNU for Windows
このプロジェクトは osdn.net/projects/mingw に移行中です。引き続きそこでフォローしていただけます。 MinGW: GNU Compiler Collection (GCC) のネイティブ Windows ポートであり、ネイティブ Windows アプリケーションを構築するための自由に配布可能なインポート ライブラリとヘッダー ファイルであり、C99 機能をサポートする MSVC ランタイムの拡張機能が含まれています。すべての MinGW ソフトウェアは 64 ビット Windows プラットフォームで実行できます。

SAP NetWeaver Server Adapter for Eclipse
Eclipse を SAP NetWeaver アプリケーション サーバーと統合します。

AtomエディタMac版ダウンロード
最も人気のあるオープンソースエディター

ホットトピック









