根据市场趋势和场景,API(应用程序编程接口)是开发人员必不可少的工具,使他们能够将第三方服务集成到他们的应用程序中。以下是 2024 年及以后各个类别中可用的免费 API 的详尽列表,以及每个 API 的网站链接、说明和示例代码。
游戏 API
Steam 社区 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 游戏 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));
语言 API
邪恶侮辱生成器 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));
有趣的翻译 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));
音乐 API
Spotify Web API
- 网站:developer.spotify.com/documentati…
- 描述:访问音乐数据,如专辑、艺术家、播放列表和用户数据。控制 Spotify 播放等。
示例代码
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));
安全 API
我被黑了吗 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));
首丹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));
科学与数学 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));
开放科学框架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));
体育 API
NBA 官方 API
- 网站:any-api.com/nba_com/nba…
- 描述:访问有关 NBA 球队、球员和比赛的数据。
示例代码
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 应用程序 API
不和谐 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));
这份 2024 年免费 API 综合列表涵盖了广泛的类别,为开发人员提供了大量机会,让他们能够通过强大而多样的功能增强其应用程序。从游戏和音乐到科学和政府数据,这些 API 为创建创新且引人入胜的项目提供了宝贵的资源。 原文地址:[dev.to/techalgospo…]
【智答专家】您身边免费的GPT4.0人工智能Ai助手,免翻!!!无套路!国内直连,支持文本生成、问答、多语言支持、个性化建议、图片生成、代码纠正等等。 t.aizdzj.com/?p=MTAwNzE2…