ユーザー名による性別判定 - 複数リクエスト
Multiple Username エンドポイントを使用すると、 一度のリクエストで最大 50 件のユーザー名の性別判定を行うことができます。 これは一括処理や高性能な統合に役立ちます。 すべてのパラメータは JSON の POST リクエストで送信します。 認証には Authorization ヘッダーによる Bearer トークン方式を使用する必要があります。
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 | 配列(オブジェクトの配列) | 必須 | ユーザー名とオプションパラメータの配列。 1 リクエストあたり最大 50 件まで送信可能です。 |
username | String | 必須(各オブジェクト内) | 性別を判定する対象のユーザー名。アンダースコア、数字などを含むことができます。 |
country | String | 任意 |
性別判定の精度向上のための 2 文字の国コード(
ISO 3166-1 alpha-2
)。
例:トルコなら TR 。
|
id | String または Integer | 任意 |
ご自身のデータベースと結果を紐づけるための任意の ID。
同じ 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 | 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 )。 |