通过邮箱获取性别 - 单次请求

Get Gender by Email 接口允许您通过分析电子邮箱地址来判断一个人的性别。 所有参数都通过 POST 请求以 JSON 格式发送。 您需要在 Authorization 头部使用 Bearer token 方式进行身份验证。

请求 URL

POST https://api.genderapi.io/api/email

必需的 HTTP 头部

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

请求体参数

参数 类型 必填 描述
email String 要分析的邮箱地址。API 会先从邮箱中提取可能的名字,然后判断性别。
country String 两位字母的国家代码(ISO 3166-1 alpha-2),用于提升预测的准确率。例如:TR 代表土耳其。
askToAI Boolean 如果设置为 true,当数据库中找不到提取到的名字时,API 会请求 AI 模型来判断性别。

请求示例


cURL 示例

curl -X POST "https://api.genderapi.io/api/email" \
     -H "Content-Type: application/json" \
     -H "Authorization: Bearer YOUR_API_KEY" \
     -d '{"email": "michael.smith@example.com", "country": "US", "askToAI": true}'

PHP cURL 示例

<?php
$url = "https://api.genderapi.io/api/email";

$data = array(
    "email" => "michael.smith@example.com",
    "country" => "US",
    "askToAI" => 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/email", {
  method: "POST",
  headers: {
    "Content-Type": "application/json",
    "Authorization": "Bearer YOUR_API_KEY"
  },
  body: JSON.stringify({
    email: "michael.smith@example.com",
    country: "US",
    askToAI: true
  })
})
.then(response => response.json())
.then(data => console.log(data));

Python requests 示例

import requests

url = "https://api.genderapi.io/api/email"

payload = {
    "email": "michael.smith@example.com",
    "country": "US",
    "askToAI": 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": "michael.smith@example.com",
  "name": "Michael",
  "gender": "male",
  "country": "US",
  "total_names": 10345,
  "probability": 97,
  "duration": "5ms"
}

响应字段说明

字段 类型 描述
status Boolean 请求是否成功。
used_credits Integer 本次请求消耗的积分数。
remaining_credits Integer 本次请求后账户剩余的积分数。
expires Integer (timestamp) 套餐过期日期(UNIX 时间戳)。
q String 您的输入查询(所提交的邮箱)。
name String 从邮箱地址提取到的名字。
gender Enum[String] 预测的性别。可能的值:malefemalenull
country String 用于预测的国家代码。
total_names Integer 本次预测使用的样本数量。
probability Integer 性别预测的置信度百分比。
duration String 请求处理所用时间(如 5ms)。