我正在尝试使用 axios
来 GET
github 的 graphQL 端点,但它一直告诉我我没有获得授权:
const handleClick = token => event =>
axios.get("https://api.github.com/graphql", {
headers: { "Authorization": "bearer" + token}
}).then(response => console.log(response))
我得到了这个错误:
GET https://api.github.com/graphql 401 (Unauthorized)
bundle.js:1475 Uncaught (in promise) Error: Request failed with status code 401
at createError (bundle.js:1475)
at settle (bundle.js:1619)
at XMLHttpRequest.handleLoad (bundle.js:1028)
createError @ bundle.js:1475
settle @ bundle.js:1619
handleLoad @ bundle.js:1028
最佳答案
您需要在“bearer”和您的 token 之间留一个空格:
"bearer " + token
关于javascript - 为什么 Github 的 GraphQL API 401 与 Axios 兼容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44610214/