I am using the following code to connect to Google Calendar 3.
Dim datafolder As String = Server.MapPath("App_Data/CalendarService.api.auth.store")
Dim scopes As IList(Of String) = New List(Of String)()
Dim UserId As String = "101935195xxxxxx-jm6o24ifgbixxxxxxxxxxxx@developer.gserviceaccount.com".Trim()
scopes.Add("https://www.googleapis.com/auth/calendar")
Dim myclientsecret As New ClientSecrets() With { _
.ClientId = myClientID, _ ' It is saved in the web config
.ClientSecret = ClientSecret _ ' It is saved in the web config
}
Dim flow As GoogleAuthorizationCodeFlow
Try
flow = New GoogleAuthorizationCodeFlow(New GoogleAuthorizationCodeFlow.Initializer() With { _
.DataStore = New FileDataStore(datafolder), _
.ClientSecrets = myclientsecret, _
.Scopes = scopes
})
Catch ex As Exception
lblerr.Text = ex.ToString
End Try
It throws:
System.TypeInitializationException: The type initializer for 'Google.Apis.Http.ConfigurableMessageHandler' threw an exception.
System.IO.FileLoadException: Could not load file or assembly 'System, Version=2.0.5.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e, Retargetable=Yes' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
What am I doing wrong with this coding? Why am I not getting authenticated?
I have seen a similar error when using external libraries (e.g. DLL's) which are downloaded from the internet. Your post doesn't mention this, but I'll post here just in case this applies to you.
Make sure any external libraries used by your project are not blocked by Windows. You can do this by right-clicking the library file (e.g. the DLL) and going to Properties. At the bottom, if this applies, there will be a button to "Unblock". Click it and then try to run your project again.
Additional info and automation options can be found here: http://www.howtogeek.com/70012/what-causes-the-file-downloaded-from-the-internet-warning-and-how-can-i-easily-remove-it/
User contributions licensed under CC BY-SA 3.0