node.js - 401 error on Analytics API using public access api key -
not how test other way, using public access api key results in result: login required
error. can google analytics not called public access key?
var google = require('googleapis') var analytics = google.analytics('v3') var c = require('./config.json') analytics.data.ga.get({ key: c.key, 'ids': c.ids, 'start-date': '2015-07-15', 'end-date': '2015-07-24', 'metrics': 'ga:sessions' })
not if google analytics api supports calls using public_api key, able achieve access using service account.
var google = require('googleapis'), analytics = google.analytics({ version: 'v3'}) key = require('./key.json'), var jwtclient = new google.auth.jwt( key.client_email, null, key.private_key, ['https://www.googleapis.com/auth/analytics.readonly'], null) analytics.data.ga.get({ 'ids': 'ga:xxxxxxx', 'start-date': startdate, 'end-date': enddate, 'metrics': 'ga:sessions', auth: jwtclient }, function (err, resp) { console.log(resp) })
Comments
Post a Comment