Google.Apis.Auth.OAuth2.Responses.TokenResponseException: invalid_grant, робот отключен - PullRequest
0 голосов
/ 20 июня 2019

Я использую Visual Studio для Mac для проекта .NET Console C # с использованием Google Speech API.

Я получаю сообщение об ошибке:

Grpc.Core.RpcException: 'Status(StatusCode=Unavailable, Detail="Getting metadata from plugin failed with error: Exception occurred in metadata credentials plugin. Google.Apis.Auth.OAuth2.Responses.TokenResponseException: Error:"invalid_grant", Description:"Robot is disabled.", Uri:""
   at Google.Apis.Auth.OAuth2.Requests.TokenRequestExtenstions.ExecuteAsync(TokenRequest request, HttpClient httpClient, String tokenServerUrl, CancellationToken taskCancellationToken, IClock clock) in C:\Apiary\support1351\Src\Support\Google.Apis.Auth\OAuth2\Requests\TokenRequestExtenstions.cs:line 52
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential.RequestAccessTokenAsync(CancellationToken taskCancellationToken) in C:\Apiary\support1351\Src\Support\Google.Apis.Auth\OAuth2\ServiceAccountCredential.cs:line 212
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.RefreshTokenAsync() in C:\Apiary\support1351\Src\Support\Google.Apis.Auth\OAuth2\TokenRefreshManager.cs:line 129
   at Google.Apis.Auth.OAuth2.TokenRefreshManager.GetAccessTokenForRequestAsync(CancellationToken cancellationToken) in C:\Apiary\support1351\Src\Support\Google.Apis.Auth\OAuth2\TokenRefreshManager.cs:line 114
   at Google.Apis.Auth.OAuth2.ServiceAccountCredential.GetAccessTokenForRequestAsync(String authUri, CancellationToken cancellationToken) in C:\Apiary\support1351\Src\Support\Google.Apis.Auth\OAuth2\ServiceAccountCredential.cs:line 235
   at Grpc.Auth.GoogleAuthInterceptors.<>c__DisplayClass2_0.<<FromCredential>b__0>d.MoveNext() in T:\src\github\grpc\src\csharp\Grpc.Auth\GoogleAuthInterceptors.cs:line 48
--- End of stack trace from previous location where exception was thrown ---
   at Grpc.Core.Internal.NativeMetadataCredentialsPlugin.GetMetadataAsync(AuthInterceptorContext context, IntPtr callbackPtr, IntPtr userDataPtr) in T:\src\github\grpc\src\csharp\Grpc.Core\Internal\NativeMetadataCredentialsPlugin.cs:line 83")'

в строке, которую я отмечаюс комментарием "// ошибка здесь" в коде:

class Program
{
    static void Main(string[] args)
    {
        var URI = "https://speech.googleapis.com/v1/speech:recognize?key=[API_KEY]";

        Console.WriteLine("Start!");

        AsyncRecognizeGcs(URI);

        Console.WriteLine("End.");

    }

    static object AsyncRecognizeGcs(string storageUri)
    {
        var speech = SpeechClient.Create();
        var longOperation = speech.LongRunningRecognize(new RecognitionConfig()
        {
            Encoding = RecognitionConfig.Types.AudioEncoding.Flac,
            SampleRateHertz = 44100,
            AudioChannelCount = 2,
            LanguageCode = "en",
        }, RecognitionAudio.FromStorageUri(storageUri)); // error here
        longOperation = longOperation.PollUntilCompleted();
        var response = longOperation.Result;
        foreach (var result in response.Results)
        {
            foreach (var alternative in result.Alternatives)
            {
                Console.WriteLine($"Transcript: { alternative.Transcript}");
            }
        }
        return 0;
    }

}

Как это исправить?Есть ли что-то еще, что мне нужно настроить с помощью Google?

Ответы [ 2 ]

1 голос
/ 21 июня 2019

Рекомендовать обновление до новой версии Google.Cloud.PubSub.V1, которая будет использовать более новую версию Grpc.Core. Используйте последнее обновление Google.Apis.Auth.

0 голосов
/ 21 июня 2019

Оказывается, у меня неверные учетные данные json-файла. Глупая ошибка.

...