【问题标题】:Could not load type 'Google.Apis.Requests.IErrorResponseHandler' from assembly 'Google.Apis'无法从程序集“Google.Apis”加载类型“Google.Apis.Requests.IErrorResponseHandler”
【发布时间】:2013-12-12 10:45:24
【问题描述】:

我是 .net 中的 Google Auth api 日历。我已经从这个链接复制了代码:Refresh Token Expiration time Google calendar 无法从程序集“Google.Apis, Version=1.6.0.16897, Culture=neutral, PublicKeyToken=null”加载类型“Google.Apis.Requests.IErrorResponseHandler”

这是我的代码:

private CalendarService CreateService(string token)
    {
        //KeyValuePair<string, string> credentials = Ninject.Web.Common.Get3LOCredentials();
        var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, this.clientID, this.ClientSecret);
        //provider.ClientIdentifier = clientID;
        //provider.ClientSecret = clientSecret;
        var auth = new Google.Apis.Authentication.OAuth2.OAuth2Authenticator<NativeApplicationClient>(provider, (p) => GetAuthorization(provider, token));
        CalendarService service = new CalendarService(new BaseClientService.Initializer()
        {
            Authenticator = auth,
            ApiKey = ConfigurationManager.AppSettings[this.APIkey].ToString(),
            GZipEnabled = false
        });
        return service;
    }

    private static IAuthorizationState GetAuthorization(NativeApplicationClient arg, String Refreshtoken)
    {
        IAuthorizationState state = new AuthorizationState(new[] { CalendarService.Scopes.Calendar.GetStringValue() });
        state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
        state.RefreshToken = Refreshtoken;
        return state;
    }

【问题讨论】:

  • 嗨!你能在哪里解决这个问题?我也有同样的问题。谢谢
  • 还没有。实际上我想保存刷新令牌,以便在我进行以下调用时可以获得未过期的访问令牌
  • 好的,但是没有令牌不应该这样工作。我的意思是,您是否使用密钥(p.12 - 文件)和凭据登录到谷歌 API?我的代码在控制台应用程序中运行良好,但是当我在 Mvc 中实现代码时,我遇到了这个问题。这是我的代码:stackoverflow.com/questions/22144085/…

标签: c# asp.net-mvc-3 oauth oauth-2.0 google-calendar-api


【解决方案1】:

您是否使用包管理器来安装 API?

进一步,您是要每次都请求访问权限,还是要保存刷新令牌,以便在进行后续调用时获得未过期的访问令牌?

【讨论】:

  • 是的,我已经使用包管理器控制台安装了 api。是的,我想保存刷新令牌,以便在进行以下调用时可以获得未过期的访问令牌
【解决方案2】:

我通过卸载并重新安装 NuGet 包“google.apis.auth”解决了这个问题。这是因为安装了多个版本。

  1. 右键单击项目的“参考”菜单。手动移除 所有与 google.apis.auth 相关的包引用。

  2. 然后,选择“管理 NuGet 包”,搜索“google.apis.auth”, 并卸载“google.apis.auth”。

  3. 重新安装相同的包。

  4. 清理并重建

如果不起作用,您也可以尝试重新安装“google.apis”。

【讨论】:

    猜你喜欢
    • 2016-01-02
    • 1970-01-01
    • 2012-05-05
    • 2010-09-19
    • 2017-11-26
    • 2020-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多