Riot API:我不知道为什么它返回未经授权(401)
我不知道为什么这会未经授权。我检查了api_key
和puuid
是正确的。当我以类似方式向另一个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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
改变“?”在'&'的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}