【发布时间】:2019-01-31 07:21:39
【问题描述】:
我正在尝试从我的节点服务器(作为 Firebase 云函数运行)连接到 Google Analytics Reporting API v4。我想使用 JWT 进行身份验证,如下例所示:http://nali.org/google-analytics-v4-api-node-js-starter-example/
但是我收到了这个错误:
Error: error:0906D06C:PEM routines:PEM_read_bio:no start line
at Error (native)
at Sign.sign (crypto.js:307:26)
at Object.sign (/user_code/node_modules/googleapis/node_modules/jwa/index.js:76:45)
at Object.jwsSign [as sign] (/user_code/node_modules/googleapis/node_modules/jws/lib/sign-stream.js:32:24)
它似乎在尝试使用 PEM 文件,但我只想使用电子邮件和私钥。这不可能吗?我提供的示例链接是否具有误导性?
这是我的代码:
const email = functions.config().ga.email;
const privateKey = functions.config().ga.privatekey;
const scope = ['https://www.googleapis.com/auth/analytics.readonly'];
const token = new googleapis.google.auth.JWT(email, null, privateKey, scope, null);
token.authorize( (error, tokens) => {
if (error) {
console.error('Error connecting to GA:', error);
} else {
console.log('Authorized!', tokens);
}
})
感谢您的帮助!
【问题讨论】:
标签: node.js google-api google-analytics-firebase google-api-nodejs-client