Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Connect to Google Analytics with a service account and the Google .net Client library
string[] scopes = new string[] {AnalyticsService.Scope.Analytics}; // view and manage your Google Analytics data
var keyFilePath = @"c:\file.p12" ; // Downloaded from
var serviceAccountEmail = ""; // found
//loading the Key file
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable);
var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(serviceAccountEmail) {
Scopes = scopes}.FromCertificate(certificate));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment