在寶可夢系列遊戲中,API Key通常用於開發者訪問官方或非官方的寶可夢相關API,以獲取遊戲數據、精靈信息、對戰數據等。以下是一些常見的用途和相關信息:
以下是一個使用PokeAPI獲取寶可夢信息的Python示例代碼:
import requests
def get_pokemon_info(pokemon_name):
url = f"https://pokeapi.co/api/v2/pokemon/{pokemon_name}"
response = requests.get(url)
if response.status_code == 200:
data = response.json()
print(f"Name: {data['name']}")
print(f"Height: {data['height']}")
print(f"Weight: {data['weight']}")
print("Abilities:")
for ability in data['abilities']:
print(f" - {ability['ability']['name']}")
else:
print("Pokemon not found.")
get_pokemon_info("pikachu")
這段代碼通過PokeAPI獲取了皮卡丘的基本信息,並列印了它的名字、身高、體重以及技能。
通過API Key,開發者可以輕鬆獲取寶可夢相關的數據,用於開發套用、分析數據或進行其他有趣的項目。