1

我正在尝试在我的应用程序中实现对 Google Drive 的使用,但我似乎收到以下错误"Method 'get_Error' in type 'Google.Apis.Drive.v2.Data.FileList' from assembly 'Google.Apis.Drive.v2, Version=1.2.4647.29713, Culture=neutral, PublicKeyToken=null' does not have an implementation"。有谁知道为什么会发生这种情况?我的代码基于 Google 为其任务 API 提供的示例。

下面的代码:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Util;
using System.Diagnostics;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
using Google.Apis.Authentication;
using Google.Apis.Authentication.OAuth2;
using Google.Apis.Authentication.OAuth2.DotNetOpenAuth;
using Google.Apis.Util;
using PrepHub.PrepHub;
using System.Web.Services;
using System.Threading;
using Google.Apis;
using Google.Apis.Drive.v2.Data;
using Google.Apis.Drive.v2;
using Google.Apis.Drive;


namespace DriveExample
{
    public partial class GDrive : System.Web.UI.Page
    {
        private static DriveService _service; // We don't need individual service instances for each client.
        private OAuth2Authenticator<WebServerClient> _authenticator;
        private IAuthorizationState _state;

        private IAuthorizationState AuthState
        {
            get
            {
                return _state ?? HttpContext.Current.Session["AUTH_STATE"] as IAuthorizationState;
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {

            if (_service == null)
            {
                _service = new DriveService(_authenticator = CreateAuthenticator());
            }


            if (HttpContext.Current.Request["code"] != null)
            {
                _authenticator = CreateAuthenticator();
                _authenticator.LoadAccessToken();
            }

            var ni = _service.Files.List().Fetch();

       }


        private OAuth2Authenticator<WebServerClient> CreateAuthenticator()
        {

            var provider = new WebServerClient(GoogleAuthenticationServer.Description);
            provider.ClientIdentifier = ClientCredentials.ClientID;
            provider.ClientSecret = ClientCredentials.ClientSecret;
            var authenticator =
                new OAuth2Authenticator<WebServerClient>(provider, GetAuthorization) { NoCaching = true };
            return authenticator;
        }

        private IAuthorizationState GetAuthorization(WebServerClient client)
        {
            // If this user is already authenticated, then just return the auth state.
            IAuthorizationState state = AuthState;
            if (state != null)
            {
                return state;
            }
            // Check if an authorization request already is in progress.
            state = client.ProcessUserAuthorization(new HttpRequestInfo(HttpContext.Current.Request));
            if (state != null && (!string.IsNullOrEmpty(state.AccessToken) || !string.IsNullOrEmpty(state.RefreshToken)))
            {
                // Store and return the credentials.
                HttpContext.Current.Session["AUTH_STATE"] = _state = state;
                return state;
            }

            string scope = DriveService.Scopes.Drive.GetStringValue();
            OutgoingWebResponse response = client.PrepareRequestUserAuthorization(new[] { scope });
            response.Send(); 
            return null;
        }

    }
}
4

1 回答 1

0

我猜你的一些程序集已经过时了。例如,当您有一个程序集时会发生该错误,比如说 foo.dll (v1) 并且该程序集被 bar.dll (v2) 引用。bar.dll 中的一个类期望 Foo 中的一个类中存在某些东西,但它不存在。Error在您的情况下,它是在 class 上调用的属性的 get 访问器FileList。仔细检查所有程序集以确保它们都是最新版本。

于 2012-09-25T20:05:25.883 回答