API İSTEMCİLERİ & KOD ÖRNEKLERİ

Yükleme talimatlarını ve kod örneklerini görmek için programlama dilini seç

Resmi PHP istemci kütüphanemiz, Composer paket yöneticisini kullanarak Gender API’yi PHP uygulamalarına entegre etmenin pratik bir yolunu sunar.

Öncelikle kütüphanemizi Composer ile yükleyin:

$ composer require gender-api/client
use GenderApi\Client as GenderApiClient;

try {
    $apiClient = new GenderApiClient('insert your API key');

    // Query a single name
    $lookup = $apiClient->getByFirstName('elisabeth');
    if ($lookup->genderFound()) {
        echo $lookup->getGender();      // female
    }

    // Query a full name and improve the result by providing a country code
    $lookup = $apiClient->getByFirstNameAndLastNameAndCountry('Thomas Johnson', 'US');
    if ($lookup->genderFound()) {
        echo $lookup->getGender();      // male
        echo $lookup->getFirstName();   // Thomas
        echo $lookup->getLastName();    // Johnson
    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient remaining requests
    // left. See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

PHP Legacy

Eski projeler veya basit entegrasyonlar için Composer bağımlılığı olmadan bağımsız PHP uygulaması.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

function getGender($firstname) {
  $myKey = 'insert your server key here';
  $data = json_decode(file_get_contents(
  'https://gender-api.com/get?key=' .
  $myKey .
  '&name=' . urlencode($firstname)));
  return $data->gender;
  }

  echo getGender('markus'); //Output: male

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

Tam IntelliSense desteği ve sıkı tip denetimi sunan, TypeScript projeleri için tür güvenli istemci.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

$ npm i gender-api.com-client --save
import {Client as GenderApiClient, ResultSingleName} from "gender-api.com-client";

const genderApiClient = new GenderApiClient("your API key");

try {
    genderApiClient.getByFirstName('theresa', (response: ResultSingleName) => {
      console.log(response.gender); //female
      console.log(response.accuracy); //98
    });

    genderApiClient.getByFirstNameAndCountry('john', 'US', (response: ResultSingleName) => {
      console.log(response.gender); //male
      console.log(response.accuracy); //99
    });
}
catch(e) {
  console.log('Error:', e);
}

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

Node.js ve tarayıcı ortamları için Promise tabanlı API’ye sahip, kullanımı kolay JavaScript istemcisi.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

$ npm i gender-api.com-client --save
try {
    var GenderApi = require('gender-api.com-client');

    var genderApiClient = new GenderApi.Client('your api key');

    genderApiClient.getByFirstName('theresa', function (response) {
        console.log(response.gender); //female
        console.log(response.accuracy); //98
    });

    genderApiClient.getByFirstNameAndCountry('john', 'US', function (response) {
        console.log(response.gender); //male
        console.log(response.accuracy); //99
    });

}
catch(e) {
    console.log('Error:', e);
}

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

Python

Temiz, okunabilir kodlu, veri bilimi, makine öğrenimi ve web uygulamaları için ideal Python API istemcisi.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Python 3.*
import json

from urllib.request import urlopen

myKey = "insert your server key here"
url = "https://gender-api.com/get?key=" + myKey + "&name=kevin"
response = urlopen(url)
decoded = response.read().decode('utf-8')
data = json.loads(decoded)
print( "Gender: " + data["gender"]); #Gender: male

Python 2.*
import json
import urllib2

myKey = "insert your servery key here"
data = json.load(urllib2.urlopen("https://gender-api.com/get?key=" + myKey + "&name=markus"))
print "Gender: " + data["gender"]; #Gender: male

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

R

R ile istatistiksel analiz ve veri bilimi süreçleri için sorunsuz entegrasyona sahip mükemmel çözüm.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

$ apt install r-cran-dplyr r-cran-httr2 r-cran-tibble r-cran-jsonlite
#' Gender API Client (single name only)
#'
#' Gets gender by a first name, optionally filtered by country.
#'
#' @param name A character string containing a single first name.
#' @param country Optional two-letter country code, see: https://gender-api.com/en/api-docs
#' @param api_key Your Gender-API.com API key.
#'
#' @return A tibble containing the estimated gender, number of samples,
#'   accuracy (0–100), and the request duration in ms.
#' @export
#'
#' @examples
#' \dontrun{
#' gender("Andrea", country="US", api_key="YOUR_KEY")
#' gender("Andrea", country="IT")
#' }
#'
library(httr2)
library(dplyr)

gender <- function(name, country = NULL, api_key = Sys.getenv("GENDER_API_KEY")) {
  if (missing(name) || length(name) != 1) {
    stop("`name` must be a single string.")
  }
  if (is.null(api_key) || api_key == "") {
    stop("API key is required. Set with `Sys.setenv(GENDER_API_KEY='your_key')` or pass via `api_key`.")
  }

  args <- list(
    key = api_key,
    name = name
  )
  if (!is.null(country)) args<- country

  resp <- request("https://gender-api.com/get") %>%
    req_url_query(!!!args) %>%
    req_perform()

  if (resp_status(resp) >= 400) {
    stop("Request failed: ", resp_status_desc(resp))
  }

  out <- resp_body_json(resp, simplifyVector = TRUE)

  tibble::as_tibble(out)
}

gender("Andrea", country="US", api_key="<YOUR API KEY>")

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

Java

Kurumsal ölçekte, sağlam ve ölçeklenebilir uygulamalar için uygun, gelişmiş hata yönetimi sunan Java implementasyonu.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import com.google.gson.Gson;
import com.google.gson.JsonObject;

public class Main {

  public static void main(String[] args) {

  try {

    String myKey = "insert your server key here";
    URL url = new URL("https://gender-api.com/get?key=" + myKey + "&name=markus");
    HttpURLConnection conn = (HttpURLConnection) url.openConnection();

    if (conn.getResponseCode() != 200) {
      throw new RuntimeException("Error: " + conn.getResponseCode());
    }

    InputStreamReader input = new InputStreamReader(conn.getInputStream());
    BufferedReader reader = new BufferedReader(input);

    Gson gson = new Gson();
    JsonObject json = gson.fromJson(reader, JsonObject.class);
    String gender = json.get("gender").getAsString();
    System.out.println("Gender: " + gender); // Gender: male
    conn.disconnect();

    } catch (IOException e) {
      e.printStackTrace();
    }
  }
}

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API

Tam async/await desteği ve modern C# özellikleriyle C# uygulamaları için .NET entegrasyonu.

Öncelikle kütüphanemizi Composer ile yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Öncelikle npm ile kütüphanemizi yükleyin:

Müşteri belgelerinin tamamını buradan görüntüleyin:

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

Örnek bir proje indirin buradan:

Belgeler:

https://github.com/microknights/Gender-API
// Contributed Client: https://github.com/microknights/Gender-API

using MicroKnights.Gender_API;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Net.Http;
using System.Threading.Tasks;

namespace GenderAPI
{
    class Program
    {
        public static async Task RunTests(GenderApiClient client)
        {
            var responseStats = await client.GetStatistics();
            if( responseStats.IsSuccess ) {
                Console.WriteLine($"IsLimitReached: {responseStats.IsLimitReached}");
                Console.WriteLine($"Remaning requests: {responseStats.RemaningRequests}");

                const string Name = "Frank Nielsen";
                var responseName = await client.GetByNameAndCountry2Alpha(Name, "DK");
                if( responseName.IsSuccess ) {
                    Console.WriteLine($"{Name} is {responseName.GenderType.DisplayName}");
                }
                else {
                    Console.WriteLine($"ERRORS: {responseName.ErrorCode}-{responseName.Exception.Message}");
                }
            }
            else {
                Console.WriteLine($"ERRORS: {responseStats.ErrorCode}-{responseStats.Exception.Message}");
            }
        }

        public static Task UsingServiceProvider(string apiKey){
            // client is thread-safe, and can be used static.
            var serviceProvider = new ServiceCollection()
                .UseGenderAPI(apiKey)
                .BuildServiceProvider();

            return RunTests(serviceProvider.GetRequiredService<GenderApiClient>());
        }

        public static Task PlainConsole(string apiKey){
            // client is thread-safe, and can be used static.
            var client = new GenderApiClient(
                new HttpClient
                {
                    BaseAddress = new Uri("https://gender-api.com")
                },
                new GenderApiConfiguration
                {
                    ApiKey = apiKey
                });
            return RunTests(client);
        }

        static async Task Main(string[] args)
        {
            var apiKey = "?";

            await PlainConsole(apiKey);
            await UsingServiceProvider(apiKey);
        }
    }
}

Başlamaya Hazır mısın?

Ücretsiz kaydol ve her ay, kredi kartı gerekmeden 100 istek al.

Sohbet