Wir verwenden Google Analytics API v3 (dot net Version) für die Berichterstattung einige statistische Daten auf unserer Website. Ich habe den Code läuft gut auf meinem lokalen Rechner, aber es würde auf dem Produktionsserver aufgrund einiger Firewall-Regeln nicht funktionieren. Unser Systemadministrator schlägt vor, einen Proxy zu verwenden. Ich suchte im Internet nach Richtlinien für die Einrichtung eines Proxy für den Google Analytics-API-Dienst, aber ohne Erfolg. Alle Hinweise in dieser Hinsicht schätzen.Route Google Analytics v3 API über einen Proxy-Server
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;
}
Können Sie Ihren Code irgendwo hochladen. Wie authentifizieren und melden die Daten.Will versuchen, dann zu helfen –
@KamranShahid: Aktualisiert die Frage mit dem Quellcode – itsbalur