xero.apiCallback 不是函数
xero.apiCallback is not a function
我的 xero 代码出现错误。它说,xero.apiCallback 不是函数。 xero 中的其他功能似乎有效。
这是我的代码:
require('dotenv').config();
const express = require('express');
const XeroRouter = express.Router();
const { XeroClient } = require('xero-node');
const { TokenSet } = require('openid-client');
const client_id = process.env.CLIENT_ID;
const client_secret = process.env.CLIENT_SECRET;
const redirectUrl = process.env.REDIRECT_URI;
const scopes = "openid profile email accounting.settings accounting.reports.read accounting.journals.read accounting.contacts accounting.attachments accounting.transactions offline_access";
const xero = new XeroClient({
clientId: client_id,
clientSecret: client_secret,
redirectUris: [redirectUrl],
scopes: scopes.split(" "),
});
if ( !client_secret || !redirectUrl) {
throw Error('Environment Variables not all set - please check your .env file in the project root or create one!')
}
XeroRouter.get('/', async (req, res) => {
try {
let consentUrl = await xero.buildConsentUrl();
res.redirect(consentUrl);
} catch (e) {
res.status(e.status || 500);
console.log(e);
}
});
XeroRouter.get("/callback", async (req, res) => {
let tokenSet = await xero.apiCallback(req.url);
console.log(req.url); //This has value
console.log(tokenSet); // this returns TokenSet {}
});
module.exports = XeroRouter;
我不确定为什么 apiCallback 不起作用,但它在文档中说它起作用。
我遇到了同样的问题并最终让它工作,我不得不实际查看节点模块的代码才能弄清楚发生了什么。
您需要在构建 XeroClient 时显式设置 openIdClient,它对我有用。
将您的构造函数更改为如下所示,它应该可以工作。
const xero = new XeroClient({
clientId: client_id,
clientSecret: client_secret,
redirectUris: [redirectUrl],
openIdClient: TokenSet,
scopes: scopes.split(" "),
});
我的 xero 代码出现错误。它说,xero.apiCallback 不是函数。 xero 中的其他功能似乎有效。
这是我的代码:
require('dotenv').config();
const express = require('express');
const XeroRouter = express.Router();
const { XeroClient } = require('xero-node');
const { TokenSet } = require('openid-client');
const client_id = process.env.CLIENT_ID;
const client_secret = process.env.CLIENT_SECRET;
const redirectUrl = process.env.REDIRECT_URI;
const scopes = "openid profile email accounting.settings accounting.reports.read accounting.journals.read accounting.contacts accounting.attachments accounting.transactions offline_access";
const xero = new XeroClient({
clientId: client_id,
clientSecret: client_secret,
redirectUris: [redirectUrl],
scopes: scopes.split(" "),
});
if ( !client_secret || !redirectUrl) {
throw Error('Environment Variables not all set - please check your .env file in the project root or create one!')
}
XeroRouter.get('/', async (req, res) => {
try {
let consentUrl = await xero.buildConsentUrl();
res.redirect(consentUrl);
} catch (e) {
res.status(e.status || 500);
console.log(e);
}
});
XeroRouter.get("/callback", async (req, res) => {
let tokenSet = await xero.apiCallback(req.url);
console.log(req.url); //This has value
console.log(tokenSet); // this returns TokenSet {}
});
module.exports = XeroRouter;
我不确定为什么 apiCallback 不起作用,但它在文档中说它起作用。
我遇到了同样的问题并最终让它工作,我不得不实际查看节点模块的代码才能弄清楚发生了什么。
您需要在构建 XeroClient 时显式设置 openIdClient,它对我有用。
将您的构造函数更改为如下所示,它应该可以工作。
const xero = new XeroClient({
clientId: client_id,
clientSecret: client_secret,
redirectUris: [redirectUrl],
openIdClient: TokenSet,
scopes: scopes.split(" "),
});