简体   繁体   English

无法使用 Google 的 node.js 客户端库生成 JWT 客户端。 运行代码时出现 Typeerror

[英]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.

相关问题 Node.js - 类型错误:客户端不是构造函数 - Node.js - TypeError: Client is not a constructor Node.js 源代码被发送到客户端 - Node.js source code getting sent over to client TypeError: jwt.split 不是 OAuth2Client.verifySignedJwtWithCertsAsync 节点上的 function package: google-auth-library - TypeError: jwt.split is not a function at OAuth2Client.verifySignedJwtWithCertsAsync Node package: google-auth-library 为client和node.js发布库 - Publish a library for client and node.js 为什么我不能在运行由Openshift托管的Node.js + Websocket的服务器上获取连接客户端的IP地址(使用WebSocket-Node) - Why can't I get the connecting client's ip address on my server running Node.js + Websocket hosted by Openshift (Using WebSocket-Node) 客户端可以访问Node.js服务器中的代码吗? - Can the code in the server of Node.js be accessed by the client? 在 Node.js 中获取客户端主机名 - Getting client hostname in Node.js Node.js:获取客户端的 IP - Node.js: Get client's IP 如何使用 node.js 客户端库以编程方式从 google-cloud-automl 获取模型 ID - How to programmatically get model id from google-cloud-automl with node.js client library 尝试使用Google API Node.js客户端时出现“找不到模块”错误 - Getting “Module not found” error when trying to use the Google APIs Node.js client
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM