当社ウェブサイトの統計データを報告するために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;
}
あなたのコードをどこかにアップロードできますか?データを認証して報告する方法は? –
@KamranShahid:質問をソースコード – itsbalur