Lay Google Analytics v3 API through a proxy server

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; } 
+6
source share
1 answer

I did not find any useful documentation on forums or on the Internet, so I decided to use the System.Net configuration on web.config.

  <system.net> <defaultProxy useDefaultCredentials="true"> <proxy proxyaddress="http://abc.com:3128" usesystemdefault="True" bypassonlocal="True"/> <bypasslist> <add address="http://xyz.com" /> <add address="http://www.example.com" /> </bypasslist> </defaultProxy> </system.net> 

Any requests that we do not want to pass through a proxy can be added to the <bypasslist> . This has the added benefit of: when changing the Google API class library, we don’t have to worry about re-writing the code to configure the proxy server. :-)

+3
source

Source: https://habr.com/ru/post/944186/


All Articles