在 C# 对话流应用程序中使用显式凭据
Using explicit credentials in a C# dialogflow application
我正在创建一个使用 DialogFlow 的 detectIntent 的 C# 应用程序。我需要帮助明确传递 Google 云凭据。
它适用于 GOOGLE_APPLICATION_CREDENTIALS 环境变量。但是我想明确地传递凭据。我需要 .
提供的解决方案的 C# 版本
我正在使用随文档提供的以下快速入门:
public static void DetectIntentFromTexts(string projectId,
string sessionId,
string[] texts,
string languageCode = "en-US")
{
var client = df.SessionsClient.Create();
foreach (var text in texts)
{
var response = client.DetectIntent(
session: new df.SessionName(projectId, sessionId),
queryInput: new df.QueryInput()
{
Text = new df.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();
}
}
目前您需要直接创建一个 gRPC 通道,并将其传递给客户端:
GoogleCredential credential = GoogleCredential.FromFile("...");
ChannelCredentials channelCredentials = credential.ToChannelCredentials();
Channel channel = new Channel(SessionsClient.DefaultEndpoint, channelCredentials);
var client = df.SessionsClient.Create(channel);
很快,通过构建器模式,这将变得容易得多:
var client = new SessionsClientBuilder
{
CredentialsPath = "path to file",
}.Build();
... 或指定凭据的各种其他方式。我希望这会在接下来的几周内发布。
我正在创建一个使用 DialogFlow 的 detectIntent 的 C# 应用程序。我需要帮助明确传递 Google 云凭据。
它适用于 GOOGLE_APPLICATION_CREDENTIALS 环境变量。但是我想明确地传递凭据。我需要
我正在使用随文档提供的以下快速入门:
public static void DetectIntentFromTexts(string projectId,
string sessionId,
string[] texts,
string languageCode = "en-US")
{
var client = df.SessionsClient.Create();
foreach (var text in texts)
{
var response = client.DetectIntent(
session: new df.SessionName(projectId, sessionId),
queryInput: new df.QueryInput()
{
Text = new df.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();
}
}
目前您需要直接创建一个 gRPC 通道,并将其传递给客户端:
GoogleCredential credential = GoogleCredential.FromFile("...");
ChannelCredentials channelCredentials = credential.ToChannelCredentials();
Channel channel = new Channel(SessionsClient.DefaultEndpoint, channelCredentials);
var client = df.SessionsClient.Create(channel);
很快,通过构建器模式,这将变得容易得多:
var client = new SessionsClientBuilder
{
CredentialsPath = "path to file",
}.Build();
... 或指定凭据的各种其他方式。我希望这会在接下来的几周内发布。