VB.NET Create Event samples

774 views
Skip to first unread message

Keith Ellis

unread,
Dec 5, 2011, 12:02:23 PM12/5/11
to google-ca...@googlegroups.com
I've been creating calendar events using v2 successfully in VB.NET where I was able to supply the username and password to gain access to a private calendars. I'm really struggling to work out how to do this with oauth2. Trying to convert the CS samples to VB isn't helping either. Can some one point me in the direction of any simple VB examples that would allow me to connect to a calendar and edit events without having to keep authorizing? Please forgive my ignorance.

Alain Vongsouvanh

unread,
Dec 6, 2011, 11:39:08 AM12/6/11
to google-ca...@googlegroups.com
Hello,

Unfortunately, I am not a VB specialist and never actually wrote code in this programming language. Are you having any specific issues? Do you get an error code or message or is your code simply not compiling?
I may be able to help you if you could give me more information as to what is not working.

Best,
Alain

On Mon, Dec 5, 2011 at 12:02 PM, Keith Ellis <ellis...@googlemail.com> wrote:
I've been creating calendar events using v2 successfully in VB.NET where I was able to supply the username and password to gain access to a private calendars. I'm really struggling to work out how to do this with oauth2. Trying to convert the CS samples to VB isn't helping either. Can some one point me in the direction of any simple VB examples that would allow me to connect to a calendar and edit events without having to keep authorizing? Please forgive my ignorance.

--
You received this message because you are subscribed to the Google Groups "Google Calendar API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-calendar-api/-/whX7GOJGTvQJ.
To post to this group, send email to google-ca...@googlegroups.com.
To unsubscribe from this group, send email to google-calendar...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-calendar-api?hl=en.



--
Alain Vongsouvanh | Developer Programs Engineer

Keith Ellis

unread,
Dec 7, 2011, 4:48:18 AM12/7/11
to google-ca...@googlegroups.com
Hello Alain, Thanks for the reply.

I've converted the C# sample from here http://code.google.com/apis/calendar/v3/using.html#client successfully and can obtain an authorization key, connect and download a list of events. What I'm struggling to work out is how to get the access and refresh tokens and use them instead if having to reauthorize every time. I've seen some other C# samples of how to do this but I'm hitting a wall trying to do the same thing in VB.net. 

Keith

Keith Ellis

unread,
Dec 7, 2011, 9:27:16 AM12/7/11
to google-ca...@googlegroups.com
Ok, I've made some progress with this. I have now managed to create access & refresh tokens using HTTP POST and GETs rather than the authenticators in the API - which were really confusing.

Now that I have an access token, is there an easy way to create a CalendarService that would take the access token as a parameter? 

Markusr

unread,
Dec 7, 2011, 10:50:56 AM12/7/11
to google-ca...@googlegroups.com
Can you post your code to help others out with similar problems?

-Markus

Keith Ellis

unread,
Dec 7, 2011, 11:11:06 AM12/7/11
to google-ca...@googlegroups.com
Ok. Where I'm at so far. I have a VB.NET application that is trying to create calendar events without having to keep reauthorising.

I've added a form with a Web browser control. This handles the initial authorisation;

        Dim s As String
        s = s & "scope=https://www.googleapis.com/auth/calendar"
        s = s & "&response_type=code"
        s = s & "&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
        s = s & "&client_id=your client id"
        s = s & "&access_type=offline"

        WebBrowser1.Navigate(New Uri(s).ToString)

I then use the DocumentTitleChanged event of the browser control to get the Authorisation code from the page title. With the Authorisation code I can get the access and refresh tokens;

        Dim s As String
        s = "code=" & lblAuthCode.Text
        s = s & "&client_id=your client id"
        s = s & "&client_secret=your client secret"
        s = s & "&redirect_uri=urn:ietf:wg:oauth:2.0:oob"
        s = s & "&grant_type=authorization_code"

        Dim oWeb As New System.Net.WebClient()

        oWeb.Headers.Add("Content-Type", "application/x-www-form-urlencoded")

        Dim bytArguments As Byte() = System.Text.Encoding.ASCII.GetBytes(s)
        Dim bytRetData As Byte() = oWeb.UploadData("https://accounts.google.com/o/oauth2/token", "POST", bytArguments)

        Dim AuthResponse As String = System.Text.Encoding.ASCII.GetString(bytRetData)

From the AuthResponse I can get the access token and the refresh token.

With the access token I can do http GETs to retrieve calendar events etc but I would still like to use the API for creating and modifying calendar events but that seems to require some sort of authenticator which is where I'm stuck. I have the keys I just need to be able to use them to create an authenticator.


Markusr

unread,
Dec 7, 2011, 11:29:35 AM12/7/11
to google-ca...@googlegroups.com
Thanks Kevin,

Just some insight on what I am doing... I am writing a c# windows service that will sync a proprietary database calendar with a Google apps business account calendar (one direction/read only).

I am doing this so far using the v2 API since the v3 .NET API seems incomplete and not supported much.

The next step I am trying to do is display the user's calendar in an embedded browser (desktop application). This is where I need to figure out what type of authentication I need. I create/maintain the user's Google account so  I am trying to find out if there is a way to create a cookie (or whatever) so the user does not have to log in to my app and then in to Google. The private calendar URL is being discontinued so I am in a bind.

-Markus

Keith Ellis

unread,
Dec 7, 2011, 11:35:30 AM12/7/11
to google-ca...@googlegroups.com
I think I'll be having the same issue down the line once I've worked out how to create the events.

Keith
Reply all
Reply to author
Forward
0 new messages