简体   繁体   中英

Unable to access Dialogflow V2 detect Intent C# Webhook

Getting following error:

System.InvalidOperationException: 'The Application Default Credentials are not available. They are available if running in Google Compute Engine. Otherwise, the environment variable GOOGLE_APPLICATION_CREDENTIALS must be defined pointing to a file defining the credentials...

public static int DetectIntentFromTexts(string projectId,
                                        string sessionId,
                                        string text,
                                        string languageCode = "en-US")
        {

            var client = SessionsClient.Create();

            var response = client.DetectIntent(
                session: SessionName.FromProjectSession(projectId, sessionId),
                queryInput: new QueryInput()
                {
                    Text = new TextInput()
                    {
                        Text = text,
                        LanguageCode = languageCode
                    }
                });

            var queryResult = response.QueryResult;

            Console.WriteLine($"Query text: {queryResult.QueryText}");
            if (queryResult.Intent != null)
            {
                Console.WriteLine($"Intent detected: {queryResult.Intent.DisplayName}");
            }
            Console.WriteLine($"Intent confidence: {queryResult.IntentDetectionConfidence}");
            Console.WriteLine($"Fulfillment text: {queryResult.FulfillmentText}");
            Console.WriteLine();

            return 0;
        }

You need to place the Credentials.json key generated from Google cloud in your code and set it to the environment variable in the start up of your project.

Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", file);

//In Global.asax.cs in case of .net framework Application //In startup.cs in case of .net core Application //In the above code line file means the local path of your credentails.json key

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM