ユーザー名による性別判定 - 単一リクエスト
Get Gender by Username エンドポイントを使用すると、
ユーザー名やニックネームを解析して性別を判定することができます。
すべてのパラメータは JSON の POST リクエストとして送信します。
認証には Authorization ヘッダーによる Bearer トークン方式を使用する必要があります。
リクエスト URL
POST https://api.genderapi.io/api/username
必須 HTTP ヘッダー
Content-Type: application/json
Authorization: Bearer YOUR_API_KEY
リクエストボディのパラメータ
パラメータ |
型 |
必須 |
説明 |
username |
String |
必須 |
判定対象のユーザー名またはニックネーム。
ソーシャルメディアのハンドル名やスクリーンネーム、エイリアスなどを指定できます。
ファンタジー用語やブランド名など、名前とは無関係の単語を含む場合もあります。
|
country |
String |
任意 |
性別予測の精度向上のための 2 文字の国コード(
ISO 3166-1 alpha-2)。
例:トルコの場合 TR 。
|
askToAI |
Boolean |
任意 |
true に設定すると、抽出した名前がデータベースに存在しない場合に
AI モデルへ問い合わせを行い、性別を判定します。
|
forceToGenderize |
Boolean |
任意 |
true に設定すると、人名とは思えない単語(例: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 レスポンス例
{
"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"
}
レスポンスフィールド
フィールド |
型 |
説明 |
status |
Boolean |
リクエストが成功したかどうか。 |
used_credits |
Integer |
このリクエストで消費したクレジット数。 |
remaining_credits |
Integer |
このリクエスト後の残りクレジット数。 |
expires |
Integer (timestamp) |
パッケージの有効期限(UNIX タイムスタンプ)。 |
q |
String |
送信した元のクエリ(ユーザー名)。 |
name |
String |
ユーザー名から抽出されたファーストネーム。 |
gender |
Enum[String] |
予測された性別。male 、female 、または null のいずれか。 |
country |
String |
予測に使用された国コード。 |
total_names |
Integer |
この予測に使用されたサンプル数。 |
probability |
Integer |
性別予測の信頼度(%)。 |
duration |
String |
リクエスト処理時間(例:6ms )。 |