To troubleshoot the issues you're facing with Azure's Face Liveness API and its integration into your C# .NET application, consider the following steps:
- Check API Key and Endpoint: Ensure that the subscription key and endpoint you are using are correct and that your Azure subscription has access to the Face service. You can verify this by checking your Azure portal.
- Session Management: The response from your first API call indicates that the status is "NotStarted." This means that the liveness detection process has not yet begun. You need to wait for the liveness session to complete before making a second call to retrieve the results. The session ID returned in the first response should be used in the second API call to check the status.
- Verify Image Quality: Ensure that the image you are using for verification meets the quality requirements. The
qualityForRecognitionfield in your response indicates that the quality is high, which is good. However, you may want to test with different images to see if the results vary. - Integration in C#: For integrating the API into your C# application, you can use the HttpClient class to make REST API calls. Here’s a basic example of how to set up a call:
Replaceusing System; using System.Net.Http; using System.Net.Http.Headers; using System.Threading.Tasks; class Program { private static readonly HttpClient client = new HttpClient(); static async Task Main() { client.DefaultRequestHeaders.Add("Ocp-Apim-Subscription-Key", "YOUR_SUBSCRIPTION_KEY"); var content = new MultipartFormDataContent(); content.Add(new StringContent("passiveactive"), "livenessOperationMode"); content.Add(new StringContent("723d6d03-ef33-40a8-9682-23a1feb7bccd"), "deviceCorrelationId"); content.Add(new StringContent("true"), "enableSessionImage"); content.Add(new ByteArrayContent(System.IO.File.ReadAllBytes("path_to_your_image.jpg")), "VerifyImage", "image.jpg"); var response = await client.PostAsync("https://faceliveness-clv-dev1.cognitiveservices.azure.com/face/v1.2/detectLivenesswithVerify-sessions", content); var responseString = await response.Content.ReadAsStringAsync(); Console.WriteLine(responseString); } }YOUR_SUBSCRIPTION_KEYandpath_to_your_image.jpgwith your actual subscription key and the path to your image file. - Postman Testing: If you are testing with Postman, ensure that you are using the correct HTTP method (POST) and that the headers and body are set correctly. The response you receive should match the expected format in the documentation.
If you continue to experience issues, consider checking the Azure documentation for any updates or changes to the API, and ensure that you are following the latest guidelines for usage.
References: