Skip to content

Commit 94d88a6

Browse files
authored
Updated authentication naming/format
1 parent d4b0b7f commit 94d88a6

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

dotnet/Language/SentimentV3.cs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,21 @@ public class Program
1212
{
1313
public class TextAnalyticsSentimentV3Client
1414
{
15-
//You can get the reqeust url by going to:
16-
//https://centralus.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-0-preview/operations/56f30ceeeda5650db055a3c9
17-
//and clicking on the region (e.g. Central US).
18-
private static readonly string textAnalyticsUrl = "<ADD_TEXT_ANALYTICS_URL_HERE>/v3.0-preview/sentiment";
15+
// You can get the reqeust url from:
16+
// https://<YOUR-REGION>.dev.cognitive.microsoft.com/docs/services/TextAnalytics-v3-0-preview/operations/56f30ceeeda5650db055a3c9
17+
private static readonly string endpoint = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_ENDPOINT") + "/v3.0-preview/sentiment";
1918

20-
private static readonly string textAnalyticsKey = "<ADD_TEXT_ANALYTICS_KEY_HERE>";
19+
private static readonly string subscriptionKey = Environment.GetEnvironmentVariable("TEXT_ANALYTICS_SUBSCRIPTION_KEY");
2120

2221
public static async Task<SentimentV3Response> SentimentV3PreviewPredictAsync(TextAnalyticsBatchInput inputDocuments)
2322
{
2423
using (var httpClient = new HttpClient())
2524
{
26-
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", textAnalyticsKey);
25+
httpClient.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", subscriptionKey);
2726

2827
var httpContent = new StringContent(JsonConvert.SerializeObject(inputDocuments), Encoding.UTF8, "application/json");
2928

30-
var httpResponse = await httpClient.PostAsync(new Uri(textAnalyticsUrl), httpContent);
29+
var httpResponse = await httpClient.PostAsync(new Uri(endpoint), httpContent);
3130
var responseContent = await httpResponse.Content.ReadAsStringAsync();
3231

3332
if (!httpResponse.StatusCode.Equals(HttpStatusCode.OK) || httpResponse.Content == null)
@@ -50,7 +49,7 @@ public static void Main(string[] args)
5049
{
5150
Id = "1",
5251

53-
Text = "Hello world. This is some input text that I love."
52+
Text = "Hello world. This is some input text."
5453
},
5554

5655
new TextAnalyticsInput()
@@ -64,7 +63,7 @@ public static void Main(string[] args)
6463
{
6564
Id = "3",
6665

67-
Text = "Pike place market is my favorite Seattle attraction."
66+
Text = "Pike place market is not my favorite Seattle attraction."
6867
}
6968
}
7069
};

0 commit comments

Comments
 (0)