title: Route Google Analytics v3 API through a proxy server
body: <p>We are using <a href="http://code.google.com/p/google-api-dotnet-client/wiki/APIs#Google_Analytics_API" rel="noreferrer">Google Analytics API v3</a>  (dot net version) for reporting some statistical data on our website. I have the code running fine on my local machine, but it wouldn't work on the production server due to some firewall rules. Our system admin suggests to try and use a proxy. I searched on the internet for any guidelines to set up proxy for Google Analytics API service, but with no luck. Appreciate any pointers in this regard.</p>
  
  <p>EDIT:</p>
  
  <pre><code>   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&lt;AssertionFlowClient&gt; auth = new OAuth2Authenticator&lt;AssertionFlowClient&gt;(
              client,
              AssertionFlowClient.GetState
              );
  
          return auth;
      }
  </code></pre>