Created
February 6, 2018 16:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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