ระบุเพศจากชื่อผู้ใช้ – คำขอหลายรายการ

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

API จะพยายามแยกชื่อที่เป็นไปได้จากแต่ละชื่อผู้ใช้ ซึ่งสามารถช่วยเพิ่มความแม่นยำในการทำนายเพศ นอกจากนี้คุณยังสามารถระบุฟิลเตอร์ country ได้ตามต้องการ และฟิลด์ id แบบกำหนดเองเพื่อจับคู่ผลลัพธ์กับระเบียนในฐานข้อมูลของคุณ

คำเตือน: โดยทั่วไปชื่อผู้ใช้ควรเป็นอักขระละติน อย่างไรก็ตามมักจะมีคำหรือการรวมกัน ที่ไม่ใช่ชื่อจริง เช่น cool_boy123

หากเป้าหมายหลักของคุณคือการทำนายเพศอย่างแม่นยำ เราขอแนะนำให้ใช้คำขอเดี่ยว โดยเปิดใช้พารามิเตอร์ forceToGenderize

หากลำดับความสำคัญของคุณคือการแยกชื่อที่เป็นไปได้จากชื่อผู้ใช้เท่านั้น ก็สามารถใช้คำขอหลายรายการแทนได้

URL สำหรับคำขอ

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

ส่วนหัว HTTP ที่จำเป็น

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

พารามิเตอร์ในเนื้อหาคำขอ

ฟิลด์ ประเภท จำเป็น คำอธิบาย
data Array of Objects ใช่ อาร์เรย์ที่มีชื่อผู้ใช้และพารามิเตอร์เสริม สามารถส่งได้สูงสุด 50 รายการในคำขอเดียว
username String ใช่ (ในแต่ละอ็อบเจ็กต์) ชื่อผู้ใช้ที่จะวิเคราะห์ อาจมีขีดล่าง ตัวเลข ฯลฯ
country String ไม่ รหัสประเทศสองตัวอักษร (ISO 3166-1 alpha-2) เพื่อเพิ่มความแม่นยำของการทำนาย
ตัวอย่าง: TH สำหรับประเทศไทย
id String หรือ Integer ไม่ รหัสที่คุณกำหนดเองเพื่อจับคู่ผลลัพธ์กับระเบียนในฐานข้อมูลของคุณ API จะส่งกลับ id เดิมในผลลัพธ์เพื่อใช้ในการจับคู่

ตัวอย่างเนื้อหาคำขอ

{
  "data": [
    { "username": "anna_smith88", "country": "US", "id": "123" },
    { "username": "michael_bauer", "country": "DE", "id": "456" },
    { "username": "giulia_rossi", "country": "IT", "id": "789" }
  ]
}

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


ตัวอย่าง cURL

curl -X POST "https://api.genderapi.io/api/username/multi/country" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{"data":[{"username":"anna_smith88","country":"US","id":"123"},{"username":"michael_bauer","country":"DE","id":"456"},{"username":"giulia_rossi","country":"IT","id":"789"}]}'

ตัวอย่าง PHP cURL

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

$data = array(
    "data" => array(
        array(
            "username" => "anna_smith88",
            "country" => "US",
            "id" => "123"
        ),
        array(
            "username" => "michael_bauer",
            "country" => "DE",
            "id" => "456"
        ),
        array(
            "username" => "giulia_rossi",
            "country" => "IT",
            "id" => "789"
        )
    )
);

$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/multi/country", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
  },
  body: JSON.stringify({
    data: [
      { username: "anna_smith88", country: "US", id: "123" },
      { username: "michael_bauer", country: "DE", id: "456" },
      { username: "giulia_rossi", country: "IT", id: "789" }
    ]
  })
})
.then(response => response.json())
.then(data => console.log(data));

ตัวอย่าง Python requests

import requests

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

payload = {
    "data": [
        { "username": "anna_smith88", "country": "US", "id": "123" },
        { "username": "michael_bauer", "country": "DE", "id": "456" },
        { "username": "giulia_rossi", "country": "IT", "id": "789" }
    ]
}

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": 3,
  "remaining_credits": 7265,
  "expires": 1717069765,
  "names": [
    {
      "name": "Anna",
      "q": "anna_smith88",
      "gender": "female",
      "country": "US",
      "total_names": 1234,
      "probability": 92,
      "id": "123"
    },
    {
      "name": "Michael",
      "q": "michael_bauer",
      "gender": "male",
      "country": "DE",
      "total_names": 5678,
      "probability": 89,
      "id": "456"
    },
    {
      "name": "Giulia",
      "q": "giulia_rossi",
      "gender": "female",
      "country": "IT",
      "total_names": 4321,
      "probability": 95,
      "id": "789"
    }
  ],
  "duration": "5ms"
}

ฟิลด์ของการตอบกลับ

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