GENDER API PYTHON

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

  }

});

We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.
Got it