Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.