【问题标题】:Why am I Getting 401 Unauthorized response from unsplash.com when i do an API request with react.js? [closed]当我使用 react.js 进行 API 请求时,为什么我会收到来自 unsplash.com 的 401 Unauthorized 响应? [关闭]
【发布时间】:2021-02-20 07:22:33
【问题描述】:

我尝试发出 API 请求以从 react.js 中解开飞溅,当我使用 client_id 查询参数传递访问密钥时,它可以工作

axios.get("https://api.unsplash.com//search/photos/?client_id=YOUR_ACCESS_KEY"

但是当我像这样通过 HTTP 授权标头执行此操作时它不起作用

onSearchSubmit(term) {
axios.get("https://api.unsplash.com//search/photos", {
  params: { query: term },
  header: {
    Authorization: "Client-ID Yme6ZcumIXpWryQ0DPc249CE0ua2Mxh66Y-4W2gPAAc",
  },
  
});

}

它显示了这个错误

"OAuth error: The access token is invalid"

【问题讨论】:

    标签: javascript reactjs api axios fetch


    【解决方案1】:

    你可能最后忘记了's',尝试使用这个:

    标题:{ 授权:“客户端 ID Yme6ZcumIXpWryQ0DPc249CE0ua2Mxh66Y-4W2gPAAc”,},

    还有更多使用 axios 进行获取请求的方法,请查看documentation

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-02-07
      • 1970-01-01
      • 1970-01-01
      • 2016-04-24
      • 1970-01-01
      • 2020-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多