Skip to content

Instantly share code, notes, and snippets.

@thewindev

thewindev/Program.cs

Created Mar 19, 2021
Embed
What would you like to do?
Retrieve fields from ID with Form Recognizer
static async Task Main(string[] args)
{
var resultUrl = await StartAnalyzingImage(); // defined here https://gist.github.com/thewindev/a3a06af46693b890e968fbf810d2b50d
IdentificationResult result;
do
{
await Task.Delay(1000); // wait 1 second before checking, otherwise the API will return 429
var json = await _client.GetStringAsync(resultUrl);
result = JsonConvert.DeserializeObject<IdentificationResult>(json);
} while (result?.Status != "succeeded");
var documentResults = result.AnalyzeResult.DocumentResults;
if (documentResults != null && documentResults.Length != 0)
{
foreach (var documentResult in documentResults)
{
Console.WriteLine($"First name: {documentResult.Fields.FirstName}, confidence: {documentResult.Fields.FirstName.Confidence}");
Console.WriteLine($"Last name: {documentResult.Fields.FirstName}, confidence: {documentResult.Fields.LastName.Confidence}");
Console.WriteLine($"Address: {documentResult.Fields.Address}, confidence: {documentResult.Fields.Address.Confidence}");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment