首页 > 解决方案 > Unsplash API 触发下载

问题描述

我正在遵循 Unsplash 文档中的触发指南。所以终点是:

GET /photos/:id/download

这是照片的示例响应:

{
  "id": "LBI7cgq3pbM",
  "width": 5245,
  "height": 3497,
  "color": "#60544D",
  "urls": { ... },
  "user": { ... },
  "links": {
    "self": "https://api.unsplash.com/photos/LBI7cgq3pbM",
    "html": "https://unsplash.com/photos/LBI7cgq3pbM",
    "download": "https://unsplash.com/photos/LBI7cgq3pbM/download", // don't use this property
    "download_location": "https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM" // use this one ;)
  }
}

“确保包含 URL 中包含的任何查询参数(如 ixid)。”

所以我的问题是什么是价值 odixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM以及如何获得它?

标签: javascriptreactjsapirest

解决方案


尝试以下

const ixid = new URLSearchParams(
  new URL("https://api.unsplash.com/photos/LBI7cgq3pbM/download?ixid=MnwxMTc4ODl8MHwxfHNlYXJjaHwxfHxwdXBweXxlbnwwfHx8fDE2MTc3NTA2MTM").search
).get("ixid");
console.log(ixid);


推荐阅读