GENDER API JAVA

أولاً قم بتثبيت مكتبتنا باستخدام 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/

import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.io.IOException;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class Main {

    public static void main(String[] args) {
        String apiKey = "YOUR_API_KEY";
        String url = "https://gender-api.com/v2/gender/by-first-name";
        String payload = "{\"first_name\":\"Theresa\"}";

        HttpClient client = HttpClient.newHttpClient();

        HttpRequest request = HttpRequest.newBuilder()
                .uri(URI.create(url))
                .header("Content-Type", "application/json")
                .header("Authorization", "Bearer " + apiKey)
                .POST(HttpRequest.BodyPublishers.ofString(payload))
                .build();

        try {
            HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

            Gson gson = new Gson();
            JsonObject json = gson.fromJson(response.body(), JsonObject.class);

            System.out.println("Gender: " + json.get("gender").getAsString());
            System.out.println("Probability: " + json.get("probability").getAsFloat());

        } catch (IOException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
محادثة