i'm not able to connect to the google calendar api via oauth2. I've downloaded the *.json file which includes my cliend-id and my cliend secret and use google's code example
'Copyright 2013 Google Inc
'Licensed under the Apache License, Version 2.0(the "License");
'you may not use this file except in compliance with the License.
'You may obtain a copy of the License at
' http://www.apache.org/licenses/LICENSE-2.0
'Unless required by applicable law or agreed to in writing, software
'distributed under the License is distributed on an "AS IS" BASIS,
'WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
'See the License for the specific language governing permissions and
'limitations under the License.
Imports System.Collections.Generic
Imports System.IO
Imports System.Threading
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.Util.Store
''' <summary>
''' An sample for the Calendar API which displays a list of calendars and events in the first calendar.
''' https://developers.google.com/google-apps/calendar/
''' </summary>
Module Program
'' Calendar scopes which is initialized on the main method.
Dim scopes As IList(Of String) = New List(Of String)()
'' Calendar service.
Dim service As CalendarService
Sub Main()
' Add the calendar specific scope to the scopes list.
Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add(CalendarService.Scope.Calendar)
' Display the header and initialize the sample.
Console.WriteLine("Google.Apis.Calendar.v3 Sample")
Console.WriteLine("==============================")
dim credential As UserCredential
Using stream As New FileStream("c:/temp/client_secrets.json", FileMode.Open, FileAccess.Read)
credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
GoogleClientSecrets.Load(stream).Secrets, scopes, "user", CancellationToken.None,
New FileDataStore("Calendar.VB.Sample")).Result
End Using
' Create the calendar service using an initializer instance
Dim initializer As New BaseClientService.Initializer()
initializer.HttpClientInitializer = credential
initializer.ApplicationName = "VB.NET Calendar Sample"
service = New CalendarService(initializer)
' Fetch the list of calendar list
Dim list As IList(Of CalendarListEntry) = service.CalendarList.List().Execute().Items()
' Display all calendars
DisplayList(list)
For Each calendar As Data.CalendarListEntry In list
' Display calendar's events
DisplayFirstCalendarEvents(calendar)
Next
Console.WriteLine("Press any key to continue...")
Console.ReadKey()
End Sub
end class
I get an mscorelib-exception in line GoogleWebAuthorizationBroker.AuthorizeAsync(... I cecked if the "stream" variable get the id and the secret, but everything is fine except the authentication.
Do anybody have an idea what i did wrong or what i should try? Which "user" do i have to insert? (I used the ******@developer.gserviceaccount.com)
i also tried this version of the code for accessing the youtube api
Private Async Function GetGredentials() As Task
Try
AddToLog("Begin: GetCredentials")
'
' ClientId and ClientSecret are found in your client_secret_*****.apps.googleusercontent.com.json file downloaded from
' the Google Developers Console ( https://console.developers.google.com).
' This sample shows the ClientID and ClientSecret in the source code.
' Other samples in the sample library show how to read the Client Secrets from the client_secret_*****.apps.googleusercontent.com.json file.
'
Dim scopes As IList(Of String) = New List(Of String)()
scopes.Add(Google.Apis.Calendar.v3.CalendarService.Scope.Calendar)
OAUth2Credential = Await GoogleWebAuthorizationBroker.AuthorizeAsync( _
New ClientSecrets With {.ClientId = "242596777308-jmpe9cq9lvr23kmgt7bgsac6ogf620k8.apps.googleusercontent.com", _
.ClientSecret = "beymodgzMv9kenB8ds2R5Bb_"}, _
scopes, "me", CancellationToken.None)
AddToLog("End: GetCredentials")
If OAUth2Credential IsNot Nothing Then
If OAUth2Credential.Token IsNot Nothing Then
AddToLog(String.Concat("Token Issued: ", OAUth2Credential.Token.Issued))
End If
End If
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Google Authorization")
End
End Try
End Function
the used id and secret are copied directly from google's api console. The code throws now an exception "application not found"
The exception stacktrace is:
bei Microsoft.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task) bei Microsoft.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccess(Task task) bei Microsoft.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) bei Microsoft.Runtime.CompilerServices.TaskAwaiter`1.GetResult() bei YouTube_API_V3_Demo.Main.VB$StateMachine_1_GetGredentials.MoveNext() in C:\Users\Michael\Downloads\Sample\YouTube_API_V3_Demo\YouTube_API_V3_Demo\Main.vb:Zeile 202.
I think that something is wrong with the oauth2 authentication, but what?? What do i have to insert in the "user" parameter?
Michael