该项目目前包含对多个版本的 Google.Apis 的引用

Posted

技术标签:

【中文标题】该项目目前包含对多个版本的 Google.Apis 的引用【英文标题】:The project currently contains references to more than one version of Google.Apis 【发布时间】:2013-12-05 21:06:47 【问题描述】:

Visual Studio 2010(2012 做同样的事情),新的 VB.Net 项目,Framework 4,为 Google 日历添加了 nuget 包:

Install-Package Google.Apis.Calendar.v3 -Pre

添加导入:

Imports Google.Apis
Imports Google.Apis.Calendar.v3
Imports Google.Apis.Calendar.v3.Data
Imports Google.Apis.Calendar.v3.EventsResource
Imports Google.Apis.Services
Imports Google.Apis.Auth.OAuth2
Imports Google.Apis.Auth
Imports Google.Apis.Util.Store
Imports System.Security.Cryptography.X509Certificates

这是我创建服务和凭据的代码:

Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add(CalendarService.Scope.Calendar)  

Dim service As CalendarService
Dim serviceAccountEmail As String = "ServiceAccountEmail@developer.gserviceaccount.com"
Dim certificate = New X509Certificate2("privatekey.p12", "notasecret", X509KeyStorageFlags.Exportable)

Dim credential As New ServiceAccountCredential(New ServiceAccountCredential.Initializer(serviceAccountEmail) With 
                                 .Scopes = scopes,
                                 .User = "myuser@there.com"
                                .FromCertificate(certificate))

service = New CalendarService(New BaseClientService.Initializer() With
                                      
                                          .HttpClientInitializer = credential,
                                          .ApplicationName = "appName"
                                      )

然后我得到“该项目当前包含对多个版本的 Google.Apis 的引用,对版本 1.6.0.16897 的直接引用和间接引用(通过'Google.Apis.Auth.OAuth2.ServiceAccountCredential')版本 1.6.0.27822。将直接引用更改为使用版本 1.6.0.27822(或更高版本)的 Google.Apis”。

如果我尝试使用 ServiceAccountCredential 或 UserCredential,我会得到这个。

几周前遇到了这个问题,使用旧版本的 Google.Apis.Auth 解决了这个问题。但是我很难让服务帐户正常工作(只会收到警告:

A first chance exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.Auth.dll

应用程序会冻结)。

所以从头开始获取最新版本并再次获取此版本,完成所有 Windows 更新,最后一个 Nuget 版本 (2.7),我是唯一遇到此问题的人吗?

【问题讨论】:

【参考方案1】:

你不是唯一一个。我昨天刚把这个修好了。服务器具有新版本的 Google.Apis.Auth 但旧版本的 Google.Apis(因此不匹配)。要解决此问题,只需从您的引用中手动删除“Google.Apis.Auth”和“Google.Apis.Auth.PlatformServices”,然后添加 1.6.0.16898 版本(在 dotnet 示例中找到)。

问题解决了!

【讨论】:

嗨,迈克,是的,这就是我第一次开始项目时修复它的方式。一切都与 UserCredential 一起工作,但希望 ServiceAccountCredential 也能工作,但不能(不会从调用中收到任何东西:“Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().项目()”。应用程序会冻结。重新开始,认为它可能在以后的版本中修复,但仍然存在版本不匹配的问题。我知道它仍在预发布中,我只是等待ServiceAccountCredential 在下一个版本中查看。

以上是关于该项目目前包含对多个版本的 Google.Apis 的引用的主要内容,如果未能解决你的问题,请参考以下文章

怎样用Google APIs和Google的应用系统进行集成----Google APIs的全部的RESTFul服务一览

Google.Apis.Requests.RequestError 权限不足 [403]

尝试切换开关以在 Google APIS Explorer 中使用 OAuth 2.0 授权请求返回 500 错误

如何包含父 Spring 项目(使用 Git 子模块)?

包含EJB的Java 8 Compiled EAR导致Payara中的java.lang.NoClassDefFoundError

对 ASP.NET Core 中的 Google OAuth 包感到困惑