0

当我在本地主机上运行我的 asp.net 应用程序时,一切正常,但是当我在 Web 服务器上发布我的应用程序时,会出现此错误:

Method 'ApplyAuthenticationToRequest' in type 'Google.Apis.Authentication.OAuth2.OAuth2Authenticator`1' from assembly 'Google.Apis.Authentication.OAuth2, Version=1.4.0.28223, Culture=neutral, PublicKeyToken=null' does not have an implementation.

这是使用分析的部分代码

...................................................

                //This is the API url which we're storing to a string
                string scope = AnalyticsService.Scopes.AnalyticsReadonly.GetStringValue();

                //For whatever reason, this is labelled wrong. It is the email address
                //that you have added as a user to your Analytics account
                string clientId = "*********@developer.gserviceaccount.com";

                //This is the physical path to the file we downloaded earlier
                //To demonstrate this, I've kept the full path to my key file.
                //Obviously, you will need to change this to match where you've
                //stored yours.
                string keyFile = @"C:\key\*************76-privatekey.p12";

                //The password Google gives you, probably the same as the one below
                string keyPassword = "notasecret";

                //Store the authentication description
                AuthorizationServerDescription desc = GoogleAuthenticationServer.Description;

                //Create a certificate object to use when authenticating
                X509Certificate2 key = new X509Certificate2(keyFile, keyPassword, X509KeyStorageFlags.Exportable);

                //Now, we will log in and authenticate, passing in the description
                //and key from above, then setting the accountId and scope
                AssertionFlowClient client = new AssertionFlowClient(desc, key)
                {
                    ServiceAccountId = clientId,
                    Scope = scope
                };

                //Finally, complete the authentication process
                //NOTE: This is the first change from the update above
                OAuth2Authenticator<AssertionFlowClient> auth =
                    new OAuth2Authenticator<AssertionFlowClient>(client, AssertionFlowClient.GetState);

                //First, create a new service object
                //NOTE: this is the second change from the update
                //above. Thanks to James for pointing this out
                AnalyticsService gas = new AnalyticsService(new BaseClientService.Initializer() { Authenticator = auth });

                //Create our query
                //The Data.Ga.Get needs the parameters:
                //Analytics account id, starting with ga:
                //Start date in format YYYY-MM-DD
                //End date in format YYYY-MM-DD
                //A string specifying the metrics

                DataResource.GaResource.GetRequest r =
                    gas.Data.Ga.Get(googleID[0]["google_analytic_id"].ToString(), "2005-01-01", DateTime.Now.ToString("yyyy-MM-dd"), "ga:visitors");

                //Specify some addition query parameters
                //    r.Dimensions = "ga:pagePath";
                r.Sort = "-ga:visitors";
                r.MaxResults = 5;

                //Execute and fetch the results of our query
                GaData d = r.Execute();
4

1 回答 1

0

我也有同样的问题。目前还没有解决方案,但是:

我使用 .net 框架 4.0 在 MVC 项目中测试 google apis,我在其中添加了带有 nugets 的 google apis。该项目在 VS Express 2012 for web 中运行良好,但是当我将项目发布到运行 .NET Framework 版本:4.0.30319 的 IIS7 服务器时,我遇到了同样的崩溃。我已经验证了这两台机器使用的是相同的程序集。

有些不同,我不知道是什么!

于 2013-08-11T23:25:35.627 回答