6

当社ウェブサイトの統計データを報告するためにGoogle Analytics API v3(ドットネット版)を使用しています。私は自分のローカルマシンで正常に動作しているコードを持っていますが、いくつかのファイアウォールルールのために本番サーバでは動作しません。私たちのシステム管理者はプロキシを試してみることを提案しています。 GoogleアナリティクスAPIサービスのプロキシを設定するためのガイドラインはインターネット上で検索されましたが、運がないためです。この点については、どんな指摘にも感謝します。Google Analytics v3 APIをプロキシサーバー経由で配信

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; 
    } 
+0

あなたのコードをどこかにアップロードできますか?データを認証して報告する方法は? –

+0

@KamranShahid:質問をソースコード – itsbalur

答えて

3

私は、フォーラムやインターネット上の任意の有用なドキュメントを見つけるので、web.configファイルにSystem.Net構成を使用することを決めていませんでした。

<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> 

我々は、プロキシを通過する必要はありません任意の要求は、<bypasslist>に追加することができます。 Google APIクラスライブラリが変更されたときはいつでも、プロキシを設定するコードを書き直す必要はありません。 :-)

+0

に追加しました。バイパスリスト

関連する問題