我已经从GitHub生成了一个令牌,我想使用GitHub接口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我也尝试过用其他方法来做这件事,但是不起作用。
发布于 2017-08-10 23:00:15
您必须像这样包括令牌的类型。
setNetworkInterface(): void{
networkInterface.use([{
applyMiddleware(req, next) {
if (!req.options.headers) {
req.options.headers = {};
}
req.options.headers.authorization = 'Bearer XXXXXXXXXXX';
req.options.headers.host = 'https://api.github.com/graphql';
next();
}
}]);
}https://stackoverflow.com/questions/45591642
复制相似问题