We use the Google Analytics API v3 (dot net version) to report some statistics on our website. My code works fine on my local machine, but it will not work on the production server due to some firewall rules. Our system administrator offers to try and use proxies. I searched the web for any recommendations on setting up a proxy for the Google Analytics API service, but no luck. Please rate any pointers in this regard.
EDIT:
public DataTable GetSearchTrends() { string GoogleAnalyticsProfileId = AppConfigManager.GetGoogleAnalyticsProfileIdForInis(); var service = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = Authenticate() }); DataResource.GaResource.GetRequest request = service.Data.Ga.Get( GoogleAnalyticsProfileId, string.Format("{0:yyyy-MM-dd}", StartDate), string.Format("{0:yyyy-MM-dd}", EndDate), GoogleAnalyticsSearchUniquesMetric ); request.Dimensions = GoogleAnalyticsSearchKeywordMetric; request.Sort = string.Concat("-", GoogleAnalyticsSearchUniquesMetric); request.MaxResults = NumberOfSearchTrendsToFetch; GaData response = request.Fetch(); return SearchTrendsHelper.ConvertToDataTable( response.Rows, SearchTrendsKeywordsExcludeList, NumberOfSearchTrendsToDisplay ); } private IAuthenticator Authenticate() { string GoogleAnalyticsServiceScope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue(); string GoogleApiServiceAccountId = AppConfigManager.GetGoogleApiServiceAccountId(); string GoogleApiServiceAccountKeyFile = AppConfigManager.GetGoogleApiServiceAccountKeyFile(); string GoogleApiServiceAccountKeyPassword = AppConfigManager.GetGoogleApiServiceAccountKeyPassword(); AuthorizationServerDescription desc = GoogleAuthenticationServer.Description; X509Certificate2 key = new X509Certificate2( HttpContextFactory.Current.Server.MapPath(GoogleApiServiceAccountKeyFile), GoogleApiServiceAccountKeyPassword, X509KeyStorageFlags.Exportable | X509KeyStorageFlags.MachineKeySet ); AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = GoogleApiServiceAccountId, Scope = GoogleAnalyticsServiceScope, }; OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>( client, AssertionFlowClient.GetState ); return auth; }
source share