1

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

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

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

这是在我的本地机器上运行的代码:

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();

谢谢

4

1 回答 1

0

只有一种可能性,如果不查看代码,您将不得不追查它;其中一条路径是错误的,需要更改。当我说“路径”时,这也可以是 IP 地址的形式,因为您正在调用不存在的东西。它在您的本地机器上运行良好(正确的路径),它在远程机器上给出了 400(错误请求),就像调用错误的地方一样。

于 2013-11-08T02:39:45.373 回答