Last active
April 15, 2019 09:08
-
-
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
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, // 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