javascript - JSON:使用 Pexels API 密钥
问题描述
我开始学习 JSON,在我的整个旅程中,我在使用 API 时没有遇到过 API 密钥。我正在尝试使用 pexels API,在这里找到https://www.pexels.com/api/documentation/?language=javascript。我获得了一个 API 密钥,如何在 JSON 中使用它。我知道这是一个荒谬的问题,但我无法找出方法。谢谢你的帮助。
解决方案
如果你仔细阅读他们给出的如何使用你的 API_KEY 的文档。
你可以在这里查看文档。
您必须将API_KEY
请求header
作为Authorization
.
curl -H "Authorization: YOUR_API_KEY" \
"https://api.pexels.com/v1/search?query=people"
JS
fetch("https://api.pexels.com/v1/search?query=people", {
headers: {
Authorization: 'YOUR_API_KEY'
})
.then(response => response.json())
.then(result => console.log(result))
.catch(err => console.log(err))
推荐阅读
- openstack - 为什么在 openstack 地平线上设置浮动 ip 时操作顺序很重要?
- r - 使用 R、Shiny、DT 和 DBI 返回查询结果后嵌入图像
- azure - Internet Explorer 11 是否无法在频道中渲染来自 QnaMaker 的图像?
- python-3.x - 如何使用 pandas 在 python 中修复错误“Writing 0 cols but got 4 aliases”
- java - 找不到我的错误在哪里。NoSuchElementException
- amazon-web-services - 无法使用密钥对连接到 EC2
- suitecrm - 客户关系管理套件,创建用户问题
- reactjs - 将 Json 文件中的值提供给选择
- r - 使用 R XML 包删除 XML 中的父节点
- c# - EF Core 是否缺少 .NET Standard 与 .NET Core 库中的任何内容?