ระบุเพศจากชื่อผู้ใช้ – คำขอแบบเดี่ยว

Get Gender by Username endpoint ช่วยให้คุณสามารถระบุเพศของบุคคล โดยการวิเคราะห์ชื่อผู้ใช้หรือนามแฝงได้ พารามิเตอร์ทั้งหมดต้องถูกส่งในรูปแบบคำขอ POST ที่เป็น JSON คุณต้องตรวจสอบสิทธิ์คำขอโดยใช้ Bearer token ในส่วนหัว Authorization

URL ของคำขอ

POST https://api.genderapi.io/api/username

HTTP Headers ที่จำเป็น

  • Content-Type: application/json
  • Authorization: Bearer YOUR_API_KEY

พารามิเตอร์ใน Request Body

พารามิเตอร์ ประเภท จำเป็น คำอธิบาย
username String ใช่ ชื่อผู้ใช้หรือนามแฝงที่ต้องการวิเคราะห์ อาจเป็นชื่อบัญชีโซเชียลมีเดีย ชื่อแสดง หรือชื่อที่ใช้แทน ซึ่งอาจรวมถึงคำแฟนตาซีหรือชื่อแบรนด์
country String ไม่ รหัสประเทศ 2 ตัวอักษรเพื่อเพิ่มความแม่นยำในการทำนาย (ISO 3166-1 alpha-2)
ตัวอย่างเช่น ใช้ TH สำหรับประเทศไทย หรือ TR สำหรับตุรกี
askToAI Boolean ไม่ หากตั้งค่าเป็น true API จะขอให้โมเดล AI ทำนายเพศ สำหรับชื่อที่ไม่มีอยู่ในฐานข้อมูล
forceToGenderize Boolean ไม่ หากตั้งค่าเป็น true API จะพยายามทำนายเพศ แม้แต่สำหรับชื่อผู้ใช้ที่ไม่คล้ายกับชื่อมนุษย์จริง (เช่น คำแฟนตาซีหรือนามแฝงอย่าง sparkling_unicorn)

คำขอตัวอย่าง


ตัวอย่าง cURL

curl -X POST "https://api.genderapi.io/api/username" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{"username": "sparkling_unicorn", "country": "US", "askToAI": true, "forceToGenderize": true}'

ตัวอย่าง PHP cURL

<?php
$url = "https://api.genderapi.io/api/username";

$data = array(
    "username" => "sparkling_unicorn",
    "country" => "US",
    "askToAI" => true,
    "forceToGenderize" => true
);

$payload = json_encode($data);

$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    "Content-Type: application/json",
    "Authorization: Bearer YOUR_API_KEY"
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);

$response = curl_exec($ch);
curl_close($ch);

echo $response;
?>

ตัวอย่าง JavaScript fetch

fetch("https://api.genderapi.io/api/username", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
  },
  body: JSON.stringify({
    username: "sparkling_unicorn",
    country: "US",
    askToAI: true,
    forceToGenderize: true
  })
})
.then(response => response.json())
.then(data => console.log(data));

ตัวอย่าง Python requests

import requests

url = "https://api.genderapi.io/api/username"

payload = {
    "username": "sparkling_unicorn",
    "country": "US",
    "askToAI": True,
    "forceToGenderize": True
}

headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
}

response = requests.post(url, headers=headers, json=payload)

print(response.json())

ตัวอย่าง JSON Response

{
  "status": true,
  "used_credits": 1,
  "remaining_credits": 4999,
  "expires": 1743659200,
  "q": "sparkling_unicorn",
  "name": "Sparkling",
  "gender": "female",
  "country": "US",
  "total_names": 9876,
  "probability": 92,
  "duration": "6ms"
}

ฟิลด์ใน Response

ฟิลด์ ประเภท คำอธิบาย
status Boolean ระบุว่าคำขอสำเร็จหรือไม่
used_credits Integer จำนวนเครดิตที่ใช้ไปกับคำขอนี้
remaining_credits Integer จำนวนเครดิตที่เหลืออยู่ในบัญชีของคุณ
expires Integer (timestamp) วันที่หมดอายุของแพ็กเกจ (เป็น UNIX timestamp)
q String ชื่อผู้ใช้ที่คุณส่งมา
name String ชื่อที่แยกออกมาจากชื่อผู้ใช้
gender Enum[String] เพศที่คาดการณ์ได้: male, female หรือ null
country String รหัสประเทศที่ใช้ในการทำนาย
total_names Integer จำนวนตัวอย่างชื่อที่ใช้ในการทำนาย
probability Integer เปอร์เซ็นต์ความมั่นใจในการทำนายเพศ
duration String ระยะเวลาที่ใช้ประมวลผลคำขอ (เช่น 6ms)