Github GraphQL API 身份验证

Duk*_*nmi 1 json github async-await graphql fetch-api

我想从 github 的 graphql api 检索数据,但我不断收到错误消息: { message: 'This endpoint requires you to be authenticated.', documentation_url: 'https://docs.github.com/v3/#authentication' } 尽管使用了令牌,但我什至生成了一个新令牌来查看另一个令牌是否已损坏。可以在https://repl.it/@DukeSanmi/AcrobaticModernLanguage#index.js找到获取数据的脚本 可能是什么问题?

eva*_*eer 5

好吧,你需要在bearer和之间留一个空格variables.githubToken,如下所示:

const headers = {
    'Content-Type': 'application/json',
    'Authorization': 'bearer ' + variables.githubToken
};
Run Code Online (Sandbox Code Playgroud)

此外,切勿在公共代码中发布 API 令牌等秘密/凭证!