0

I'm trying to generate an access token via a JWT client using Google's node.js client library as mentioned here.

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

Anyone know what's causing this?

1 Answer 1

1

You'll need google-auth-library: npm install google-auth-library

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.