GENDER API JAVA

PHP with Composer

Command line

$ composer require gender-api/client


<?php

use GenderApi\Client as GenderApiClient;


try {

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

$name = $apiClient->getByFirstName('elisabeth');


if ($name->genderFound()) {

echo $name->getGender(); // will return "female" (possible values: male, female, unknown)

}


} catch (GenderApi\Exception $e) {

// Name lookup failed due to a network error or insufficient requests left

// See https://gender-api.com/en/api-docs/error-codes

echo 'Exception: ' . $e->getMessage();

}

Link zur Client-Dokumentation auf Github:

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

PHP

<?php


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

Java

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();

    }

  }

}

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

jQuery

// This example makes use of our jQuery Plugin. Click here for more infos.

//add this code to your HTML within the <head> tag

<script type="text/javascript" src="https://gender-api.com/js/jquery/gender.min.js"></script>

//Javascript Code

$('input#firstname').genderApi({key: genderApiClientKey}).on('gender-found', function(e, result) {

  if (result.accuracy >= 60) {

    alert('Gender found: ' + result.gender);

  }

});

Cookies erleichtern die Bereitstellung unserer Dienste. Mit der Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies verwenden.
OK