I need to authorize from Google analytics to get the response data.
var google = require('googleapis'),
q = require('q'),
SERVICE_ACCOUNT_EMAIL = '838823084353-cjjoiv9di67fuh7geqgggociibataf9v@developer.gserviceaccount.com',
SERVICE_ACCOUNT_KEY_FILE = __dirname + '/google-services-private-key.pem';
var def = q.defer();
var gAnalytics = google.analytics('v3');
var authClient = new google.auth.JWT( SERVICE_ACCOUNT_EMAIL, SERVICE_ACCOUNT_KEY_FILE, null, ['https://www.googleapis.com/auth/analytics.readonly']);
console.log(authClient)
authClient.authorize(function (err, tokens) {
if (err) {
console.log("err is: " + err, tokens);
return;
}
But it fails to authorize
getting error
JWT { transporter: DefaultTransporter {}, clientId_: undefined, clientSecret_: undefined, redirectUri_: undefined, opts: {},
credentials: { refresh_token: 'jwt-placeholder', expiry_date: 1 },
email: '838823084353-cjjoiv9di67fuh7geqgggociibataf9v@developer.gserviceaccount.com', keyFile: '/home/aaa/Desktop/ampretailer/server/google-services-private-key.pem', key: null, scopes: [ 'https://www.googleapis.com/auth/analytics.readonly' ], subject: undefined, gToken: [Function: GoogleToken] } err is: Error: invalid_grant: Invalid JWT Signature. { access_token: null, token_type: 'Bearer', expiry_date:null }
I recommend you try using Google Analytics v4 instead of v3 there are a number of dimensions and metrics which you will not have access to using V3.
Code ripped from analyticsReporting/batchGet.js
code ripped from samples/jwt.js