为什么此代码返回HttpError:错误的凭据?

时间:2019-07-13 12:39:56

标签: github-api octokit-js

const fs = require("fs");
const path = require("path");
const propertiesParser = require("properties-parser");
const Octokit = require('@octokit/rest');
let octokit;
let token;
let config;

const file = fs.readFileSync(path.join(process.env.HOME || process.env.USERPROFILE, ".settings"), "utf8");
const props = propertiesParser.parse(file);
config = props.TOKEN;

octokit = new Octokit({
auth: config,
})

上面的代码返回UnhandledPromiseRejectionWarning: HttpError: Bad credentials

我尝试将auth: config替换为auth: 'actualtokenfromGithub'并起作用,但是对我来说,为什么这行不通,因为config和'actualtokenfromGithub'均为字符串类型。

const fs = require("fs");
const path = require("path");
const propertiesParser = require("properties-parser");
const Octokit = require('@octokit/rest');
let octokit;
let token;
let config;

const file = fs.readFileSync(path.join(process.env.HOME || process.env.USERPROFILE, ".settings"), "utf8");
const props = propertiesParser.parse(file);
config = props.TOKEN;

octokit = new Octokit({
auth: 'actualtokenfromGithub',
})

0 个答案:

没有答案