2024你不得不知道的免费API(30+个)

1,497 阅读4分钟

前言

API(应用程序编程接口)是开发人员必不可少的工具,使他们能够将第三方服务集成到他们的应用程序中。以下是 2024 年各个类别的免费 API 的详尽列表,以及每个 API 的网站链接、说明和示例代码。

游戏类

Steam Community API

  • 官网: steamcommunity.com/dev
  • 简介: Steamworks Web API 提供了各种 Steam 功能(例如用户身份验证、库存管理和游戏数据)的接口。
  • 示例:
const fetch = require('node-fetch');

const steamApiKey = 'YOUR_STEAM_API_KEY';
const steamId = 'STEAM_USER_ID';
const url = `http://api.steampowered.com/ISteamUser/GetPlayerSummaries/v0002/?key=${steamApiKey}&steamids=${steamId}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Riot Games API

  • 官网: developer.riotgames.com
  • 简介: 访问《英雄联盟》、《云顶之弈》、《Valorant》等游戏的数据。提供有关比赛、排名、冠军和其他游戏相关统计数据。
  • 示例:
const fetch = require('node-fetch');

const riotApiKey = 'YOUR_RIOT_API_KEY';
const summonerName = 'SUMMONER_NAME';
const url = `https://na1.api.riotgames.com/lol/summoner/v4/summoners/by-name/${summonerName}?api_key=${riotApiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

语言类

Evil Insult Generator API

  • 官网: evilinsult.com/api
  • 简介: 为了好玩或测试目的,用各种语言随机生成侮辱性话语。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://evilinsult.com/generate_insult.php?lang=en&type=json';

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Fun Translations API

  • 官网: funtranslations.com/api
  • 简介: 将文本翻译成各种有趣的语言,如尤达语言、莎士比亚语言、小黄人语言等等。
  • 示例:
const fetch = require('node-fetch');

const text = 'Hello, world!';
const url = `https://api.funtranslations.com/translate/yoda.json?text=${encodeURIComponent(text)}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

音乐类

Spotify Web API

const fetch = require('node-fetch');

const accessToken = 'YOUR_SPOTIFY_ACCESS_TOKEN';
const url = 'https://api.spotify.com/v1/me/player/recently-played';

fetch(url, {
  headers: {
    'Authorization': `Bearer ${accessToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

安全类

Have I Been Pwned API

  • 官网: haveibeenpwned.com/API/v2
  • 简介: 检查您的电子邮件或用户名是否已遭遇数据泄露。提供有关泄露、粘贴和密码泄露的数据。
  • 示例:
const fetch = require('node-fetch');

const email = 'test@example.com';
const url = `https://haveibeenpwned.com/api/v2/breachedaccount/${email}`;

fetch(url, {
  headers: {
    'User-Agent': 'Node.js'
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

hodan API

  • 官网: developer.shodan.io
  • 简介: Shodan 是一个互联网连接设备的搜索引擎。它提供全球各种服务器、设备和系统的数据。
  • 示例:
const fetch = require('node-fetch');

const shodanApiKey = 'YOUR_SHODAN_API_KEY';
const query = 'apache';
const url = `https://api.shodan.io/shodan/host/search?key=${shodanApiKey}&query=${query}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

科学类

NASA API

  • 官网: api.nasa.gov
  • 简介: 访问 NASA 数据集中的数据,包括天文照片、行星数据等。
  • 示例:
const fetch = require('node-fetch');

const nasaApiKey = 'YOUR_NASA_API_KEY';
const url = `https://api.nasa.gov/planetary/apod?api_key=${nasaApiKey}`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Wolfram Alpha API

  • 官网: products.wolframalpha.com/api
  • 简介: 提供对 Wolfram Alpha 的大量计算知识的访问,包括数学计算、数据分析等。
  • 示例:
const fetch = require('node-fetch');

const wolframAppId = 'YOUR_WOLFRAM_APP_ID';
const query = 'integrate x^2';
const url = `http://api.wolframalpha.com/v2/query?input=${encodeURIComponent(query)}&appid=${wolframAppId}&output=json`;

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Open Science Framework API

  • 官网: developer.osf.io
  • 简介: 从开放科学框架访问研究数据、项目管理工具和其他科学资源。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://api.osf.io/v2/nodes/';

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

体育类

NBA API

const fetch = require('node-fetch');

const url = 'https://api-nba-v1.p.rapidapi.com/teams/league/standard';
const options = {
  method: 'GET',
  headers: {
    'X-RapidAPI-Key': 'YOUR_RAPIDAPI_KEY',
    'X-RapidAPI-Host': 'api-nba-v1.p.rapidapi.com'
  }
};

fetch(url, options)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Web应用类

Discord API

  • 官网: discord.com/developers/…
  • 简介: 将您的应用程序与 Discord 集成,允许进行用户身份验证、消息传递等。
  • 示例:
const fetch = require('node-fetch');

const discordToken = 'YOUR_DISCORD_BOT_TOKEN';
const url = 'https://discord.com/api/users/@me';

fetch(url, {
  headers: {
    'Authorization': `Bot ${discordToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Slack API

  • 官网: api.slack.com
  • 简介: 访问 Slack 功能,例如消息传递、用户数据和工作区管理。
  • 示例:
const fetch = require('node-fetch');

const slackToken = 'YOUR_SLACK_API_TOKEN';
const url = 'https://slack.com/api/conversations.list';

fetch(url, {
  headers: {
    'Authorization': `Bearer ${slackToken}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

产品类

Car Query API

  • 官网: carqueryapi.com
  • 简介: 访问汽车数据,包括品牌、型号和年份信息。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://www.carqueryapi.com/api/0.3/?cmd=getMakes';

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

Yelp API

  • 官网: yelp.com/developers
  • 简介: 访问本地企业的数据,包括评论、评级和企业详情。
  • 示例:
const fetch = require('node-fetch');

const yelpApiKey = 'YOUR_YELP_API_KEY';
const url = 'https://api.yelp.com/v3/businesses/search?location=San Francisco';

fetch(url, {
  headers: {
    'Authorization': `Bearer ${yelpApiKey}`
  }
})
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

健康类

Healthcare.gov API

  • 官网: healthcare.gov/developers
  • 简介: 访问有关医疗保健计划、提供商目录和其他健康相关信息的数据。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://data.healthcare.gov/resource/xyz123.json';

fetch(url)
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error('Error:', error));

政府和地理类

Code.gov API

  • 官网: code.gov
  • 简介: 访问联邦政府软件项目的数据,包括代码存储库和项目详细信息。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://api.code.gov/projects';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Data.gov API

  • 官网: data.gov/developers/…
  • 简介: 访问美国政府的广泛数据集,包括天气、教育和健康数据。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://api.data.gov/ed/collegescorecard/v1/schools.json?api_key=YOUR_DATA_GOV_API_KEY';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Data.europa.eu API

  • 官网: data.europa.eu/en
  • 简介: 访问来自欧盟机构和团体的开放数据。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://data.europa.eu/api/hub/search/datasets';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

TransLoc API

const fetch = require('node-fetch');

const translocApiKey = 'YOUR_TRANSLOC_API_KEY';
const url = 'https://transloc-api-1-2.p.rapidapi.com/agencies.json';

fetch(url, {
    headers: {
        'X-RapidAPI-Key': translocApiKey,
        'X-RapidAPI-Host': 'transloc-api-1-2.p.rapidapi.com'
    }
})
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

食品类

Open Food Facts API

const fetch = require('node-fetch');

const url = 'https://world.openfoodfacts.org/api/v0/product/737628064502.json';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Taco Fancy API

  • 官网: github.com/evz/tacofan…
  • 简介: 获取有关墨西哥玉米卷食谱的数据,包括原料和制作方法。
  • 示例:
const fetch = require('node-fetch');

const url = 'http://taco-randomizer.herokuapp.com/random/';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

开源项目类

Libraries.io API

  • 官网: libraries.io/api
  • 简介: 访问有关开源项目的数据,包括依赖信息、版本历史记录等。
  • 示例:
const fetch = require('node-fetch');

const librariesApiKey = 'YOUR_LIBRARIES_IO_API_KEY';
const url = `https://libraries.io/api/platforms?api_key=${librariesApiKey}`;

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

电影和漫画类

Chuck Norris Jokes API

const fetch = require('node-fetch');

const url = 'https://api.chucknorris.io/jokes/random';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Final Space API

  • 官网: finalspaceapi.com
  • 简介: 访问《太空终界》电视节目的数据,包括角色、剧集等。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://finalspaceapi.com/api/v0/character';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Kitsu API

  • 官网: kitsu.docs.apiary.io
  • 简介:访问动漫和漫画的数据,包括系列信息、评论和用户评分。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://kitsu.io/api/edge/anime';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Marvel API

  • 官网: developer.marvel.com
  • 简介: 访问有关漫威漫画、人物和创作者的数据。
  • 示例:
const fetch = require('node-fetch');

const marvelPublicKey = 'YOUR_MARVEL_PUBLIC_KEY';
const marvelPrivateKey = 'YOUR_MARVEL_PRIVATE_KEY';
const ts = new Date().getTime();
const hash = require('crypto').createHash('md5').update(ts + marvelPrivateKey + marvelPublicKey).digest('hex');
const url = `https://gateway.marvel.com/v1/public/characters?ts=${ts}&apikey=${marvelPublicKey}&hash=${hash}`;

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

PokeAPI

  • 官网: pokeapi.co
  • 简介:访问有关 Pokémon 的数据,包括种类、能力和游戏信息。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://pokeapi.co/api/v2/pokemon/ditto';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Rick and Morty API

  • 官网: rickandmortyapi.com
  • 简介: 访问 Rick and Morty 电视节目的数据,包括角色、剧集和地点。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://rickandmortyapi.com/api/character';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Simpsons Quotes API

const fetch = require('node-fetch');

const url = 'https://thesimpsonsquoteapi.glitch.me/quotes';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Star Wars API

  • 官网: swapi.tech
  • 简介: 访问有关星球大战宇宙的数据,包括电影、人物、星际飞船和行星。
  • 示例:
const fetch = require('node-fetch');

const url = 'https://swapi.tech/api/people/1';

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

Superhero API

  • 官网: superheroapi.com
  • 简介: 访问有关各种超级英雄的数据,包括他们的力量、传记和图像。
  • 示例:
const fetch = require('node-fetch');

const superheroApiKey = 'YOUR_SUPERHERO_API_KEY';
const url = `https://superheroapi.com/api/${superheroApiKey}/1`;

fetch(url)
    .then(response => response.json())
    .then(data => console.log(data))
    .catch(error => console.error('Error:', error));

总结

2024 年免费 API 的完整列表涵盖了广泛的类别,为开发人员提供了大量机会,以强大而多样的功能增强他们的应用程序。从游戏和音乐到科学和政府数据,这些 API 为创建创新且引人入胜的项目提供了宝贵的资源。 请随意探索这些 API 并将其集成到您的项目中,以解锁新的可能性和功能。祝您编码愉快!