谷歌分析apis不在生产中工作

时间:2013-11-08 02:33:08

标签: google-analytics

我正在尝试使用google analytics apis v3将分析图表嵌入我的网站使用证书文件。我让它在本地机器上工作,但当我将代码部署到我的Web服务器时,它会产生这个错误:

远程服务器返回错误:(400)错误请求。

有谁知道导致此错误消息的原因以及为什么我无法在我的生产网站上获取Google图表?

以下是在本地计算机上运行的代码:

string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue(),
                   x509Certificate2File = HttpContext.Current.Server.MapPath("~/App_Data/privatekey.p12"),
                   x509Certificate2FilePassword = "notasecret",
                   serviceAccountId = "xxxxxxx@developer.gserviceaccount.com",
                   profileId = "ga:xxxxxxxx",
                startDate = "2013-10-06",
           endDate = "2013-11-07";

            AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;

            X509Certificate2 key = new X509Certificate2(x509Certificate2File, x509Certificate2FilePassword, X509KeyStorageFlags.Exportable);

            AssertionFlowClient client = new AssertionFlowClient(desc, key) { ServiceAccountId = serviceAccountId, Scope = scope };

            OAuth2Authenticator<AssertionFlowClient> auth = new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

            AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });

    DataResource.GaResource.GetRequest request = gas.Data.Ga.Get(profileId, startDate, endDate, "ga:visits");

    request.Dimensions = "ga:day";
    request.MaxResults = 10;

    /* error 400 occur here on the production */
    Google.Apis.Analytics.v3.Data.GaData data = request.Execute();

由于

1 个答案:

答案 0 :(得分:0)

只有一种可能性而且没有查看代码,你将不得不追逐它;其中一条路径是错误的,需要更改。这可能是一个IP地址的形式,当我说“路径”时,你正在调用不存在的东西。它在你的本地机器上运行正常(正确的路径),并且在远程调用错误请求时给出了400(错误的请求)。