ระบุเพศจากชื่อ - คำขอเดียว (Get Gender by Name - Single Request)
จุดเชื่อมต่อ Get Gender by Name ช่วยให้คุณสามารถระบุเพศจากชื่อแรกได้หนึ่งชื่อ
พารามิเตอร์ทั้งหมดจะถูกส่งผ่านคำขอแบบ POST ในรูปแบบ JSON
คุณต้องยืนยันตัวตนโดยใช้ Bearer token ในส่วนหัว Authorization
URL สำหรับการร้องขอ (Request URL)
POST https://api.genderapi.io/api
HTTP Headers ที่จำเป็น
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
พารามิเตอร์ของข้อมูลที่ส่ง (Request Body Parameters)
พารามิเตอร์ | ประเภท | จำเป็นหรือไม่ | คำอธิบาย |
---|---|---|---|
name | String | จำเป็น | ชื่อแรกที่คุณต้องการวิเคราะห์ ต้องเป็นคำเดียว ไม่มีคำนำหน้า |
country | String | ไม่จำเป็น |
รหัสประเทศแบบสองตัวอักษร (ISO 3166-1 alpha-2) เพื่อเพิ่มความแม่นยำในการทำนาย ตัวอย่าง: TH สำหรับประเทศไทย
|
askToAI | Boolean | ไม่จำเป็น |
หากตั้งค่าเป็น true API จะใช้โมเดล AI เพื่อระบุเพศเมื่อไม่พบชื่อในฐานข้อมูล
|
forceToGenderize | Boolean | ไม่จำเป็น |
หากตั้งค่าเป็น true API จะพยายามคาดเดาเพศแม้ชื่อจะไม่ใช่ชื่อมนุษย์ทั่วไป เช่น ชื่อเล่นหรือคำแฟนตาซี (เช่น sparkling unicorn )
|
ตัวอย่างคำขอ (Example Requests)
ตัวอย่าง cURL
curl -X POST "https://api.genderapi.io/api" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer YOUR_API_KEY" \
-d '{"name": "Alice", "country": "US", "askToAI": true, "forceToGenderize": true}'
ตัวอย่าง PHP cURL
<?php
$url = "https://api.genderapi.io/api";
$data = array(
"name" => "Alice",
"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", {
method: "POST",
headers: {
"Content-Type": "application/json",
"Authorization": "Bearer YOUR_API_KEY"
},
body: JSON.stringify({
name: "Alice",
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"
payload = {
"name": "Alice",
"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
{
"status": true,
"used_credits": 1,
"remaining_credits": 4999,
"expires": 1743659200,
"q": "Alice",
"name": "Alice",
"gender": "female",
"country": "US",
"total_names": 10234,
"probability": 98,
"duration": "4ms"
}
คำอธิบายฟิลด์ผลลัพธ์
ฟิลด์ | ประเภท | คำอธิบาย |
---|---|---|
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 | เวลาที่ใช้ในการประมวลผลคำขอ (เช่น 4ms ) |
คำเตือน:
โปรดตรวจสอบให้แน่ใจว่าค่าที่ป้อน เช่น ชื่อ ไม่มีอักขระที่ไม่คาดคิด
หากคุณวางแผนจะใช้ตัวอักษรพิเศษหรือช่องว่าง กรุณาเข้ารหัส JSON อย่างถูกต้องเพื่อหลีกเลี่ยงข้อผิดพลาด
หากคุณวางแผนจะใช้ตัวอักษรพิเศษหรือช่องว่าง กรุณาเข้ารหัส JSON อย่างถูกต้องเพื่อหลีกเลี่ยงข้อผิดพลาด