6

Używamy Google Analytics API v3 (wersja dot net) do zgłaszania niektórych danych statystycznych na naszej stronie. Mam kod działający dobrze na moim komputerze lokalnym, ale nie działałby on na serwerze produkcyjnym ze względu na niektóre reguły zapory ogniowej. Nasz administrator systemu sugeruje użycie proxy. Szukałem w Internecie jakichkolwiek wskazówek, jak skonfigurować proxy dla usługi Google Analytics API, ale bez powodzenia. Doceń wszelkie wskazówki w tym zakresie.Trasa Google Analytics v3 API przez serwer proxy

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

Czy możesz przesłać swój kod gdzieś.Jak uwierzytelniasz i raportujesz dane. Spróbuj pomóc, następnie –

+0

@KamranShahid: Zaktualizowałeś pytanie za pomocą kodu źródłowego – itsbalur

Odpowiedz

3

Nie mogę znaleźć żadnej użytecznej dokumentacji na forach lub w Internecie, więc postanowiłem wykorzystać konfigurację System.Net na 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> 

Wszelkie prośby nie chcemy przechodzić przez proxy, może być dodawany do <bypasslist>. Ma tę dodatkową zaletę, że za każdym razem, gdy zmienia się biblioteka klas Google API, nie musimy martwić się ponownym pisaniem kodu, aby skonfigurować serwer proxy. :-)

+0

Czy możesz podać mi listę przedmiotów, które dodałeś pomiń listę:

Powiązane problemy