作成環境
- 言語:c#
- Nuget:Google.Cloud.Vision.V1 v2.4.0
- 開発ソフト:Visual Studio 2013
google cloud visionを使用して、渡した画像の文字を取得するプログラムを組んでいます。
無効化したjsonファイルで作成したclientに対して、DetectDocument()を行うとエラーが発生するので、DetectDocumentの前に、jsonファイルが有効なのか、無効なのかを判断して、処理を中止したいです。
発生するエラーは下記になります。
型 ‘Grpc.Core.RpcException’ のハンドルされていない例外が TestOCR.dll で発生しました
追加情報:Status(StatusCode=“Unauthenticated”, Detail=“Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.", DebugException=“Grpc.Core.Internal.CoreErrorDetailException: {“created”:”@1644195460.050000000”,“description”:“Error received from peer ipv4:216.58.220.106:443”,“file”:"…\src\core\lib\surface\call.cc",“file_line”:1067,“grpc_message”:"Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential. See https://developers.google.com/identity/sign-in/web/devconsole-project.",“grpc_status”:16}")
文字認識は以下のコードになります。
var clb = new ImageAnnotatorClientBuilder();
clb.CredentialsPath = "./key.json";
ImageAnnotatorClient client;
client = clb.Build();
var Result = client.DetectDocumentText("./Image.png");