Visual Studio 2010 (2012 does the same thing), new VB.Net project, Framework 4, added nuget packages for Google Calendar:
Install-Package Google.Apis.Calendar.v3 -Pre
Added Imports:
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
This is my code to create the service and credentials:
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"
})
I then got the "The project currently contains references to more than one version of Google.Apis, a direct reference to version 1.6.0.16897 and an indirect reference (through 'Google.Apis.Auth.OAuth2.ServiceAccountCredential') to version 1.6.0.27822. Change the direct reference to use version 1.6.0.27822 (or higher) of Google.Apis".
I get this if I try to use ServiceAccountCredential or UserCredential.
Had this problem a few weeks back, resolved it with using an older version of Google.Apis.Auth. But I had a hard time getting Service Accounts working (would just receive a warning:
A first chance exception of type 'Google.Apis.Auth.OAuth2.Responses.TokenResponseException' occurred in Google.Apis.Auth.dll
and app would freeze).
So started from scratch to get the latest version and got this again, all Windows Updates done, last Nuget version (2.7), Am I the only one with this problem ?