Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@mskutta
Created May 11, 2015 17:59
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 mskutta/5849165ef99f49418995 to your computer and use it in GitHub Desktop.
Save mskutta/5849165ef99f49418995 to your computer and use it in GitHub Desktop.
Social Sort Manager.cs
private AnalyticsService GetService()
{
// Google Analytics API Service Account Authentication
var keyFilePath = _settings.GoogleAnalyticsKeyFilePath; // found in developer console under APIs & auth / Credentials
var serviceAccountEmail = _settings.GoogleAnalyticsServiceAccountEmail; // found in developer console under APIs & auth / Credentials
var certificate = new X509Certificate2(keyFilePath, "notasecret", X509KeyStorageFlags.Exportable); // notasecret is the standard password for the key file.
var credential = new ServiceAccountCredential(new ServiceAccountCredential.Initializer(serviceAccountEmail)
{
Scopes = new[] { AnalyticsService.Scope.AnalyticsReadonly }
}.FromCertificate(certificate));
// Google Analytics Service
var service = new AnalyticsService(new BaseClientService.Initializer
{
HttpClientInitializer = credential,
ApplicationName = "OneNorth.SocialSort", // This can be whatever you want
});
return service;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment