【发布时间】:2018-01-17 09:36:22
【问题描述】:
我从 GitHub 生成了一个令牌,我想使用 GitHub API v4,但我必须先进行身份验证。我试过这段代码:
const networkInterface = createBatchingNetworkInterface({
uri: 'https://api.github.com/graphql',
batchInterval: 10
});
我有一个错误
This endpoint requires you to be authenticated.
所以我正在尝试使用我的令牌进行身份验证,但它不起作用。我在示例中尝试这样做:
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {}; // Create the header object if needed.
}
req.options.headers['Authorization'] = 'mytokenishere';
next();
}
}]);
在这种情况下,我会收到一条信息:
Bad credentials
我也尝试过用其他方式来做到这一点,但它不起作用。
【问题讨论】:
-
您的
Authorization标头只是mytokenishere还是bearer mytokenishere? -
嗯,这只是 mytokenishere。
-
尝试在您的令牌中包含
bearer作为令牌类型。 GitHub v4 API 文档在这里引用了它:developer.github.com/v4/guides/forming-calls/…,我假设Bad credentials表示它没有正确读取它,因为你没有包含令牌类型。
标签: angular authentication github-api apollo