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 網路 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));

安全API

我被偷了嗎 API

  • 網址haveibeenpwned.com/API/v2

  • 描述:檢查您的電子郵件或使用者名稱是否屬於資料外洩的一部分。提供有關違規、貼上和密碼洩露的資料。

範例程式碼

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

const email = '[email protected]';
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應用程式介面

範例程式碼

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));

網路應用 API

Discord API

範例程式碼

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));

產品和事物 API

汽車查詢API

品牌、型號和年份資訊。

範例程式碼

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));

健康API

醫療保健.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));

政府和地理 API

程式碼.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));

資料政府API

  • 網址data.gov/developers/apis

  • 描述:存取美國政府提供的各種資料集,包括天氣、教育和健康資料。

範例程式碼

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));

資料.europa.eu API

範例程式碼

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));

傳輸定位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));

食品原料藥

開放食品事實 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));

塔克花式 API

範例程式碼

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));

開源專案 API

圖書館.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));

電影和漫畫 API

查克諾里斯笑話 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));

最終空間 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));

木津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));

漫威API

  • 網址developer.marvel.com

  • 描述:存取有關 Marvel 漫畫、角色和創作者的資料。

範例程式碼

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));

戳API

  • 網址pokeapi.co

  • 描述:存取神奇寶貝的資料,包括物種、能力和遊戲資訊。

範例程式碼

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));

瑞克和莫蒂 API

  • 網址rickandmortyapi.com

  • 描述:存取瑞克和莫蒂電視節目的資料,包括角色、劇集和地點。

範例程式碼

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));

辛普森一家行情 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));

星際大戰 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));

超級英雄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 並將它們整合到您的專案中,以解鎖新的可能性和功能。快樂編碼!


原文出處:https://dev.to/dk119819/free-apis-you-need-to-know-about-in-2024-2ieg


共有 0 則留言