我們正在使用Google Analytics API v3(點網版)報告我們網站上的一些統計數據。我的代碼在本地機器上運行良好,但由於某些防火牆規則,它不適用於生產服務器。我們的系統管理員建議嘗試使用代理。我在互聯網上搜索了關於爲Google AnalyticsAPI服務設置代理的任何指導,但沒有運氣。欣賞這方面的任何指針。通過代理服務器路由谷歌分析v3 API
編輯:
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;
}
你可以上傳你的代碼在什麼地方。如何驗證和報告數據。將盡力幫助 – 2013-05-07 17:02:04
@KamranShahid:用源代碼更新了問題 – itsbalur 2013-05-08 16:15:39