Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbchudasama/434ff9138ca12e657ad1bf5254aafc0c to your computer and use it in GitHub Desktop.
Save dbchudasama/434ff9138ca12e657ad1bf5254aafc0c to your computer and use it in GitHub Desktop.
Code snippet for creating a Service Account Credential for Service Account Authentication with Google Analytics Core Reporting API
string[] scopes = new string[] { AnalyticsService.Scope.Analytics };
var keyPath = “<path>”;
var serviceAccountEmail = “<email>”;
//Loading the Key file
var certificate = new X509Certificate2(keyPath, <privateKey>, X509KeyStorageFlags.MachineKeySet | X509KeyStorageFlags.Exportable);
var initializer = new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
User = serviceAccountEmail,
Scopes = scopes
}.FromCertificate(certificate);
var credential = new ServiceAccountCredential(initializer);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment