How to authenticate to Google Analytics Reporting API v4

Found out what I was missing :

  • Google APIs Client Library "Options" :

    google.options({ auth: oauth2Client }); //this one is not very optional
    
  • Unlike Google Analytics Reporting API v4 documentation, queries using the client library must have headers to specify a client for each requests (thanks to CVarisco who notice that, client library documentation isn't really accurate..) :

    var request ={
        'headers': {'Content-Type': 'application/json'},
        'auth': oauth2Client,
        'resource': req,
    };