Riot API:我不知道为什么它返回未经授权(401)

发布于 2025-02-06 09:52:35 字数 567 浏览 2 评论 0原文

我不知道为什么这会未经授权。我检查了api_keypuuid是正确的。当我以类似方式向另一个Riot API提出请求时,我得到了所需的结果(状态代码:200)。我猜URL中有一个发送请求的错字,但是我找不到它出错的地方。

import fetch from 'node-fetch'

const getMatchList = async () => {
  const puuid = 'XXXXXXXX'
  const api_key = 'XXXXXXX'
  const res = await fetch(
    `https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1?api_key=${api_key}`
  )
  const myJson = await res.json()
  console.log(myJson) // { status: { message: 'Unauthorized', status_code: 401 } }
}

I don't know why this would be unauthorized. I checked that the api_key and puuid are correct. When I made a request to another Riot API in a similar way, I got the desired result (status code: 200). I'm guessing there is a typo in the URL that sent the request, but I can't find where it went wrong.

import fetch from 'node-fetch'

const getMatchList = async () => {
  const puuid = 'XXXXXXXX'
  const api_key = 'XXXXXXX'
  const res = await fetch(
    `https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1?api_key=${api_key}`
  )
  const myJson = await res.json()
  console.log(myJson) // { status: { message: 'Unauthorized', status_code: 401 } }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

辞取 2025-02-13 09:52:35

改变“?”在'&'的api_key中就是这样:
原始:https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/qun/qul$ {puuid}/ids?start = 0& count = 0& count = 1?api_key = $ {api_key}

右:https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/qun/qul {puuid}/ids?start = 0& count = 1& api_key = $ {api_key}

Change the '?' in the api_key for '&' just like that:
Original: https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1?api_key=${api_key}

Right: https://asia.api.riotgames.com/lol/match/v5/matches/by-puuid/${puuid}/ids?start=0&count=1&api_key=${api_key}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文