为什么Github的GraphQL API与Axios一起使用?

时间:2017-06-17 23:04:15

标签: javascript github graphql axios

我正在使用GET尝试使用axios 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

1 个答案:

答案 0 :(得分:2)

你需要在" bearer"之间留出空间。和你的令牌:

"bearer " + token