C# 如何在.NET SDK上使用APIKey和URL进行身份验证
如何在.NET SDK()上使用APIKey和URL()进行身份验证 SDK示例有C# 如何在.NET SDK上使用APIKey和URL进行身份验证,c#,ibm-watson,speech-to-text,C#,Ibm Watson,Speech To Text,如何在.NET SDK()上使用APIKey和URL()进行身份验证 SDK示例有SpeechToTextService(用户名、密码)但是现在Watson凭证只有APIKey和URL const string SERVICE_NAME = "speech_to_text"; const string URL = "https://stream.watsonplatform.net/speech-to-text/api"; public SpeechToTextServ
SpeechToTextService(用户名、密码)
但是现在Watson凭证只有APIKey和URL
const string SERVICE_NAME = "speech_to_text";
const string URL = "https://stream.watsonplatform.net/speech-to-text/api";
public SpeechToTextService() : base(SERVICE_NAME) { }
public SpeechToTextService(string userName, string password) : base(SERVICE_NAME, URL)
{
if (string.IsNullOrEmpty(userName))
throw new ArgumentNullException(nameof(userName));
if (string.IsNullOrEmpty(password))
throw new ArgumentNullException(nameof(password));
this.SetCredential(userName, password);
}
public SpeechToTextService(TokenOptions options) : base(SERVICE_NAME, URL)
{
if (string.IsNullOrEmpty(options.IamApiKey) && string.IsNullOrEmpty(options.IamAccessToken))
throw new ArgumentNullException(nameof(options.IamAccessToken) + ", " + nameof(options.IamApiKey));
if (!string.IsNullOrEmpty(options.ServiceUrl))
{
this.Endpoint = options.ServiceUrl;
}
else
{
options.ServiceUrl = this.Endpoint;
}
_tokenManager = new TokenManager(options);
}
public SpeechToTextService(IClient httpClient) : base(SERVICE_NAME, URL)
{
if (httpClient == null)
throw new ArgumentNullException(nameof(httpClient));
this.Client = httpClient;
}
请参阅中的IAM关键示例。您可以像这样提供密钥和URL
IamApiKey = "<iam-apikey>",
ServiceUrl = "<service-endpoint>"
IamApiKey=“”,
ServiceUrl=“”
另外,请查看有关使用ibm credentials.env文件的信息