[英]Can't generate JWT client with Google's node.js client library. Getting Typeerror while running the code
I'm trying to generate an access token via a JWT client using Google's node.js client library as mentioned here.我正在尝试使用此处提到的 Google 的 node.js 客户端库通过 JWT 客户端生成访问令牌。
Here's the code snippet I'm following:这是我正在关注的代码片段:
const { google } = require('googleapis')
const key = require('./auth.json')
const scopes = 'https://www.googleapis.com/auth/analytics.readonly'
const jwt = new google.auth.JWT(key.client_email, null, key.private_key, scopes)
const view_id = 'Your View ID'
jwt.authorize((err, response) => {
google.analytics('v3').data.ga.get(
{
auth: jwt,
ids: 'ga:' + view_id,
'start-date': '30daysAgo',
'end-date': 'today',
metrics: 'ga:pageviews'
},
(err, result) => {
console.log(err, result)
}
)
})
But I keep getting this error message:但我不断收到此错误消息:
TypeError: Cannot read property 'auth' of undefined TypeError:无法读取未定义的属性“身份验证”
Anyone know what's causing this?有谁知道这是什么原因造成的?
You'll need google-auth-library: npm install google-auth-library
你需要 google-auth-library: npm install google-auth-library
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.