目次

Google APIの呼び出し時に 'The service searchconsole has thrown an exception. HttpStatusCode is Unauthorized. API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.' エラーが発生する

Google Search Console APIの呼び出し時に 'The service searchconsole has thrown an exception. HttpStatusCode is Unauthorized. API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal.' エラーが発生する現象について紹介します。

現象

Google Search Console APIの呼び出し時に次のエラーが発生します。
エラーメッセージ
Google.GoogleApiException: 'The service searchconsole has thrown an exception. HttpStatusCode is Unauthorized. API keys are not supported by this API. Expected OAuth2 access token or other authentication credentials that assert a principal. See https://cloud.google.com/docs/authentication'

原因

原因はいくつかありますが、OAuth 2.0 クライアント IDでの認証をサポートしていないAPIの場合にこのエラーが発生します。 サービスアカウントで認証してAPIを呼び出す方式に変更するとAPIの呼び出しができる場合があります。

著者
iPentecのメインプログラマー
C#, ASP.NET の開発がメイン、少し前まではDelphiを愛用
掲載日: 2022-05-12
iPentec all rights reserverd.