After creating an account, you will be assigned a unique access key. To authenticate with the ipapi API interface, simply append your access_key parameter.
Example request:
https://api.ipapi.com/api/161.185.160.93?access_key=YOUR_ACCESS_KEY
Keep your API access key safe: your API access key is private and should be kept secure. You can disable your API access key immediately using your account dashboard at any time.
Example API response:
{
"ip": "161.185.160.93",
"type": "ipv4",
"continent_code": "NA",
"continent_name": "North America",
"country_code": "US",
"country_name": "United States",
"region_code": "NY",
"region_name": "New York",
"city": "Bath Beach",
"zip": "11201",
"latitude": 40.69459915161133,
"longitude": -73.99063873291016,
"msa": "35620",
"dma": "501",
"radius": 30.012950897216797,
"ip_routing_type": "fixed",
"connection_type": "tx",
"location": {
"geoname_id": 5108111,
"capital": "Washington D.C.",
"languages": [
{
"code": "en",
"name": "English",
"native": "English"
}
],
"country_flag": "http://assets.ipapi.com/flags/us.svg"
}
}
这道题展示的是如何调用 ipapi 地理位置接口:先获取并保护好自己的 access key,然后把它作为 query 参数追加到请求地址中,例如对指定 IP 发起查询即可返回完整的 JSON 结果。解题核心不是算法,而是理解 API 鉴权方式、请求 URL 的拼接规则,以及响应中常见字段如国家、地区、城市、经纬度和语言信息的含义。