GENDER API CSHARP

أولاً قم بتثبيت مكتبتنا باستخدام composer:

شاهد وثائق العميل الكاملة هنا:

https://github.com/markus-perl/gender-api-client

أولاً قم بتثبيت مكتبتنا باستخدام npm:

شاهد وثائق العميل الكاملة هنا:

https://github.com/markus-perl/gender-api-client-npm

أولاً قم بتثبيت مكتبتنا باستخدام npm:

شاهد وثائق العميل الكاملة هنا:

https://github.com/markus-perl/gender-api-client-npm

أولاً، ثبّت مكتبتنا باستخدام pip:

شاهد وثائق العميل الكاملة هنا:

https://github.com/markus-perl/gender-api-client-python
https://pypi.org/project/gender-api-client/

using System;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

public record GenderResponse(
    [property: JsonPropertyName("first_name")] string FirstName,
    [property: JsonPropertyName("gender")] string Gender,
    [property: JsonPropertyName("probability")] double Probability
);

public class Program
{
    public static async Task Main()
    {
        var apiKey = "YOUR_API_KEY"; // Get your key at https://gender-api.com/en/account/auth-tokens
        using var client = new HttpClient();

        var requestBody = new { first_name = "Theresa" };
        var jsonContent = new StringContent(
            JsonSerializer.Serialize(requestBody), 
            Encoding.UTF8, 
            "application/json");

        // Add Authorization header
        client.DefaultRequestHeaders.Add("Authorization", $"Bearer {apiKey}");

        try 
        {
            // Send POST request to API V2
            var response = await client.PostAsync("https://gender-api.com/v2/gender/by-first-name", jsonContent);
            response.EnsureSuccessStatusCode();

            // Parse response
            var jsonResponse = await response.Content.ReadAsStringAsync();
            var result = JsonSerializer.Deserialize<GenderResponse>(jsonResponse);

            Console.WriteLine($"Gender: {result.Gender}");
            Console.WriteLine($"Probability: {result.Probability}");
        }
        catch (Exception ex)
        {
            Console.WriteLine($"Error: {ex.Message}");
        }
    }
}
محادثة