”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 您应该知道的顶级免费API

您应该知道的顶级免费API

发布于2025-03-23
浏览:305

Top Free APIs You Should Know使用API​​或应用程序编程接口对于创建当代软件至关重要。他们从不同的平台和服务提供申请对应用通信,数据共享以及服务访问。 API可以简化您的开发过程并节省时间,无论您是您创建移动应用程序,Web应用程序还是其他类型的软件。本文将研究您应该在2024年应了解的十个免费API,提供代码示例,以帮助您了解如何使用它们,并浏览一些用例。

通过为您的应用程序提供预制的建筑物,API简化了开发过程。为了管理付款,天气信息,用户识别等功能,您可以集成当前服务,而不是从头开始创建它们。没有提供高级服务资金的初创公司,业余爱好者和小型企业可能会从免费的API中受益。

这是您应该知道的前10个免费API:

openweather api

开放式API是用于访问实时天气数据的最受欢迎的免费API之一。它使您可以为任何城市或地区检索当前的天气,预测和历史天气数据。
    用例
  1. OpenWeather非常适合需要实时天气更新的应用程序,例如旅行应用程序,活动计划者或环境监视系统。

导入请求 api_key =“ your_api_key” 城市=“伦敦” url = f“ http://api.openweathermap.org/data/2.5/weather? 响应= requests.get(url) weather_data = wendesp.json() 打印(f“城市:{weather_data ['name']}”) 打印(f“天气:{weather_data ['weather'] [0] ['description']}”)

当前天气数据

最多16天的天气预报


参考:OpenWeather API Documentation
import requests

api_key = "your_api_key"
city = "London"
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"

response = requests.get(url)
weather_data = response.json()

print(f"City: {weather_data['name']}")
print(f"Weather: {weather_data['weather'][0]['description']}")

github api

GitHub API是与GitHub存储库进行交互的绝妙工具。您可以自动化任务,例如管理问题,拉请请求,甚至为存储库事件设置Webhooks。

用例

GitHub API对于从事开源项目,自动化存储库管理以及将版本控制功能集成到其应用程序的开发人员至关重要。

    访问存储库信息
  1. 管理问题并拉请求

免费tier提供对公共存储库的无限访问

参考:github api documentation

[2

用例

您可以使用Newsapi显示最新的新闻头条,搜索特定主题或按技术,政治或体育等类别进行过滤新闻。
import requests

api_key = "your_api_key"
city = "London"
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"

response = requests.get(url)
weather_data = response.json()

print(f"City: {weather_data['name']}")
print(f"Weather: {weather_data['weather'][0]['description']}")
导入请求 api_key =“ your_api_key” url = f“ https://newsapi.org/v2/top-headlines? 响应= requests.get(url) news = wendesp.json() 对于新闻['文章']中的文章: 打印(f“ title:{atrate ['title']}”)

从数千个新闻来源

访问头条新闻

按主题,区域或出版物进行过滤新闻

免费tier允许每天1000个请求

参考:newsapi documentation

    Twitter API
Twitter API允许开发人员将Twitter的实时社交媒体数据集成到其应用程序中。您可以获取推文,用户配置文件和趋势。

用例

使用Twitter API监视趋势,获取用户推文或跟踪特定主题标签或主题的参与度。这对于社交媒体仪表板,内容营销工具和情感分析特别有用。

中获取用户推文

导入斜纹 api_key =“ your_api_key” api_secret =“ your_api_secret” auth = twepy.appauthhandler(api_key,api_secret) api = twepy.api(auth) tweets = api.user_timeline(screat_name =“ elonmusk”,count = 5) 对于推文中的推文: print(f“ {tweet.user.screen_name}:{tweet.text}”)


访问公共推文和用户数据

import requests

api_key = "your_api_key"
url = f"https://newsapi.org/v2/top-headlines?country=us&apiKey={api_key}"

response = requests.get(url)
news = response.json()

for article in news['articles']:
    print(f"Title: {article['title']}")

免费层提供对公共推文的访问

参考:Twitter API Documentation

coingecko api

Coingecko API提供加密货币市场数据,包括实时价格,交易量,市值和历史数据。它支持6000多个加密货币。

用例
  1. 非常适合加密货币投资组合跟踪应用程序,市场分析平台或将实时价格提要集成到财务应用中。
导入请求 url =“ https://api.coingecko.com/api/v3/simple/price?ids=bitcoin ,, ereum&vs_currencies=usd” 响应= requests.get(url) data = reverse.json() 打印(f“比特币:$ {data ['bitcoin'] ['usd']}”) print(f“以太坊:$ {data ['ethereum'] ['usd']}”)

实时加密货币价格

支持超过6000个加密货币

免费tier提供了对各种端点的访问


参考:Coingecko API Documentation

import tweepy

api_key = "your_api_key"
api_secret = "your_api_secret"
auth = tweepy.AppAuthHandler(api_key, api_secret)
api = tweepy.API(auth)

tweets = api.user_timeline(screen_name="elonmusk", count=5)

for tweet in tweets:
    print(f"{tweet.user.screen_name}: {tweet.text}")
openai api

OpenAI API提供了对GPT-4等功能强大的AI模型的访问权限,允许开发人员构建生成文本,回答问题甚至创建对话代理的应用程序。

用例

导入OpenAi OpenAI.API_KEY =“ your_api_key” 提示=“解释在Web开发中使用API​​的好处。” 响应= openai.completion.create( 引擎=“ text-davinci-003”, 提示=提示, max_tokens = 100 ) 打印(响应。选择[0] .Text.Strip())

基于AI的文本生成和处理
  1. 用于各种用例的NLP功能
有限请求的免费层

参考:OpenAI API Documentation

Firebase API是一个综合平台,用于构建和运行Web和移动应用程序,提供实时数据库,身份验证,托管和云功能。
用例

import requests

url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd"

response = requests.get(url)
data = response.json()

print(f"Bitcoin: ${data['bitcoin']['usd']}")
print(f"Ethereum: ${data['ethereum']['usd']}")

const firebase = require('firebase/app'); 需要('Firebase/Database'); const firebaseconfig = { Apikey:“ your_api_key”, authdomain:“ your_project.firebaseapp.com”, 数据库:“ https://your_project.firebaseio.com”, }; firebase.initializeapp(firbaseconfig); const db = firebase.database(); db.ref('users/')。设置({ 用户名:“ John Doe”, 电子邮件:“ [email protected]” });

实时数据库

身份验证服务

免费tier为小规模应用程序提供基本功能

参考:firebase api document

  1. NASA API

NASA API提供了大量空间数据的访问,包括图像,视频以及有关行星,星星和其他天体对象的信息。

用例

NASA API非常适合可视化或使用空间数据的教育应用程序,以空格为主题的网站以及应用程序。

中获取NASA日期的图像

导入请求 api_key =“ your_api_key” url = f“ https://api.nasa.gov/planetary/apod?api_key = {papi_key}” 响应= requests.get(url) data = reverse.json() 打印(f“ title:{data ['title']}”) 打印(f“ url:{data ['url']}”)

访问太空图像和数据
import requests

api_key = "your_api_key"
city = "London"
url = f"http://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"

response = requests.get(url)
weather_data = response.json()

print(f"City: {weather_data['name']}")
print(f"Weather: {weather_data['weather'][0]['description']}")

免费访问公共数据集

的免费层

参考:NASA API Documentation

Jikan API

Jikan API是免费的API

用例
  1. 导入请求 动漫“牛仔bebop”的Anime_id = 1#ID url = f“ https://api.jikan.moe/v3/anime/ {anime_id}” 响应= requests.get(url) data = reverse.json() 打印(f“ title:{data ['title']}”) print(f“概要:{data ['supropopsis'}”)

详细详细的动漫和漫画信息

支持通过流行,受欢迎程度和播放状态进行过滤

免费层提供对所有公共端点的无限访问

参考:Jikan API Documentation

import tweepy

api_key = "your_api_key"
api_secret = "your_api_secret"
auth = tweepy.AppAuthHandler(api_key, api_secret)
api = tweepy.API(auth)

tweets = api.user_timeline(screen_name="elonmusk", count=5)

for tweet in tweets:
    print(f"{tweet.user.screen_name}: {tweet.text}")

猫事实API是一种有趣而古怪的API,提供了有关猫的随机事实。这是一个轻松的API,但对于想要为用户提供有趣而有趣的内容的应用程序和网站来说,这是一个很好的补充。

用例

此API非常适合娱乐应用程序,有趣的小部件,甚至是您的用户每日有趣的事实。

随机猫事实

免费tier提供无限访问
  1. 参考:CAT事实API Documentation
结论

API是强大的工具,可以显着增强应用程序的功能,而无需您从头开始构建所有内容。本文中涵盖的10个免费API可以帮助您添加诸如天气更新,加密货币数据,社交媒体集成,甚至是AI-Driven的文本生成的功能。

这些API不仅提供免费的层次,还为各个级别的开发人员提供了强大的文档和易于使用的接口。无论您是构建简单的应用程序还是复杂的平台,这些API都可以帮助您节省时间,并专注于为用户构建独特功能。

集成这些API只是编写几行代码的问题,如示例所示。现在,您知道要探索哪个API,开始与它们进行实验,以了解如何将您的开发过程提升到一个新的水平!

版本声明 本文转载于:https://dev.to/nilebits/top-10-free-apis-you-should-know-525f?1如有侵犯,请联系[email protected]删除
最新教程 更多>

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3