Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@LindaLawton
Last active April 15, 2019 09:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LindaLawton/d67711f3cf544f57475b to your computer and use it in GitHub Desktop.
Save LindaLawton/d67711f3cf544f57475b to your computer and use it in GitHub Desktop.
How to connect to Google Analytics with Oauth2 and the .net client library
string[] scopes = new string[] {
AnalyticsService.Scope.Analytics, // view and manage your Google Analytics data
AnalyticsService.Scope.AnalyticsEdit, // Edit and manage Google Analytics Account
AnalyticsService.Scope.AnalyticsManageUsers, // Edit and manage Google Analytics Users
AnalyticsService.Scope.AnalyticsReadonly}; // View Google Analytics Data
var clientId = "[Client ID]"; // From https://console.developers.google.com
var clientSecret = "xxx"; // From https://console.developers.google.com
// here is where we Request the user to give us access, or use the Refresh Token that was previously stored in %AppData%
var credential = GoogleWebAuthorizationBroker.AuthorizeAsync(new ClientSecrets { ClientId = clientId,
ClientSecret = clientSecret},
scopes,
Environment.UserName,
CancellationToken.None,
new FileDataStore("Daimto.GoogleAnalytics.Auth.Store")).Result;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment