通过用户名获取性别 - 批量请求
Multiple Username 接口允许你在一次请求中分析最多 50 个用户名的性别。 这对于批量处理和高性能集成非常有用。 所有参数通过 JSON 格式的 POST 请求发送。你必须在 Authorization 请求头中 使用 Bearer token 进行身份验证。
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 | 对象数组 | 是 | 包含用户名及其可选参数的数组。每次请求最多允许 50 个条目。 |
username | String | 是(每个对象中) | 需要分析的用户名。可以包含下划线、数字等。 |
country | String | 否 |
用于提高预测准确度的两位字母国家代码
(ISO 3166-1 alpha-2)。
例如:土耳其为 TR 。
|
id | String 或 Integer | 否 |
可选的 ID,用于将结果与你数据库中的记录匹配。
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 响应示例
{
"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 时间戳格式。 |
names | 对象数组 | 每个输入用户名的结果列表。 |
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 。 |