FaceSessionClient.CreateLivenessSessionAsync Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Overloads
CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken) |
Create a new detect liveness session. |
CreateLivenessSessionAsync(RequestContent, RequestContext) |
[Protocol Method] Create a new detect liveness session.
|
CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken)
- Source:
- FaceSessionClient.cs
Create a new detect liveness session.
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>> CreateLivenessSessionAsync (Azure.AI.Vision.Face.CreateLivenessSessionContent body, System.Threading.CancellationToken cancellationToken = default);
abstract member CreateLivenessSessionAsync : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>>
override this.CreateLivenessSessionAsync : Azure.AI.Vision.Face.CreateLivenessSessionContent * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Azure.Response<Azure.AI.Vision.Face.CreateLivenessSessionResult>>
Public Overridable Function CreateLivenessSessionAsync (body As CreateLivenessSessionContent, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Response(Of CreateLivenessSessionResult))
Parameters
Body parameter.
- cancellationToken
- CancellationToken
The cancellation token to use.
Returns
Exceptions
body
is null.
Examples
This sample shows how to call CreateLivenessSessionAsync.
Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
CreateLivenessSessionContent body = new CreateLivenessSessionContent(LivenessOperationMode.Passive)
{
SendResultsToClient = true,
DeviceCorrelationIdSetInClient = true,
DeviceCorrelationId = "your_device_correlation_id",
AuthTokenTimeToLiveInSeconds = 60,
};
Response<CreateLivenessSessionResult> response = await client.CreateLivenessSessionAsync(body);
Remarks
Please refer to https://learn.microsoft.com/rest/api/face/liveness-session-operations/create-liveness-session for more details.
Applies to
CreateLivenessSessionAsync(RequestContent, RequestContext)
- Source:
- FaceSessionClient.cs
[Protocol Method] Create a new detect liveness session.
- This protocol method allows explicit creation of the request and processing of the response for advanced scenarios.
- Please try the simpler CreateLivenessSessionAsync(CreateLivenessSessionContent, CancellationToken) convenience overload with strongly typed models first.
public virtual System.Threading.Tasks.Task<Azure.Response> CreateLivenessSessionAsync (Azure.Core.RequestContent content, Azure.RequestContext context = default);
abstract member CreateLivenessSessionAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
override this.CreateLivenessSessionAsync : Azure.Core.RequestContent * Azure.RequestContext -> System.Threading.Tasks.Task<Azure.Response>
Public Overridable Function CreateLivenessSessionAsync (content As RequestContent, Optional context As RequestContext = Nothing) As Task(Of Response)
Parameters
- content
- RequestContent
The content to send as the body of the request.
- context
- RequestContext
The request context, which can override default behaviors of the client pipeline on a per-call basis.
Returns
The response returned from the service.
Exceptions
content
is null.
Service returned a non-success status code.
Examples
This sample shows how to call CreateLivenessSessionAsync and parse the result.
Uri endpoint = new Uri("<endpoint>");
AzureKeyCredential credential = new AzureKeyCredential("<key>");
FaceSessionClient client = new FaceSessionClient(endpoint, credential);
using RequestContent content = RequestContent.Create(new
{
livenessOperationMode = "Passive",
sendResultsToClient = true,
deviceCorrelationIdSetInClient = true,
deviceCorrelationId = "your_device_correlation_id",
authTokenTimeToLiveInSeconds = 60,
});
Response response = await client.CreateLivenessSessionAsync(content);
JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement;
Console.WriteLine(result.GetProperty("sessionId").ToString());
Console.WriteLine(result.GetProperty("authToken").ToString());
Applies to
Azure SDK for .NET