How to use the v3 calendar in C#

677 views
Skip to first unread message

Andrew Truckle

unread,
Jun 28, 2014, 2:33:23 PM6/28/14
to google-ca...@googlegroups.com
Hi

Sorry if this is a stupid question but I can't find any examples for C# about how to perform some basic tasks like:

Connecting to the calendar service.
Listing available calendars.

I can't quite get my head around all this authentification etc which was not needed in v2.

Thank you very much for any qguidance to learnign how to do this.

I have done the Google account bit with teh dash boarda nd made a project and set it to work with the calendar etc.

Thanks.

Andrew

Gleb Chermennov

unread,
Jun 30, 2014, 4:43:24 AM6/30/14
to google-ca...@googlegroups.com
Just read up on OAuth and how it works, and this article seems to be a good place to start on authentication - http://nanovazquez.com/2013/01/18/working-with-google-calendar-on-dotnet/
And of course there's official docs on auth - https://developers.google.com/accounts/docs/OAuth2WebServer
Please notice that this blog post does NOT use latest NuGet packages for v3 Calendar API.

суббота, 28 июня 2014 г., 22:33:23 UTC+4 пользователь Andrew Truckle написал:

Andrew Truckle

unread,
Jun 30, 2014, 4:52:55 AM6/30/14
to google-ca...@googlegroups.com
Thanks. Sadly I am finding all this over my head. I am also a little frustrated about how the eventual thing is going to work.

I have a C++ executable that currently calls a v2 DLL written in C#. This writes calendar events and uses the users username / password / chosen calendar.

But with this new way it is going to want to open a browser session etc. Seems very ugly to me, particularly since my routine may be called several times.

That said, when I tried making a method to connect, and then want to call it in C++, the method has a parameter IUnknown** and I don't know how to do it. All a headache to me.


--
You received this message because you are subscribed to a topic in the Google Groups "Google Calendar API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-calendar-api/VaLsSDqnauQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-calendar...@googlegroups.com.
To post to this group, send email to google-ca...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-calendar-api.
For more options, visit https://groups.google.com/d/optout.

Gleb Chermennov

unread,
Jun 30, 2014, 11:55:49 AM6/30/14
to google-ca...@googlegroups.com
Well, if you're letting THAT frustrate you, then I don't know. But I wouldn't want to tackle interop + Google Calendar - every one is a trouble itself

понедельник, 30 июня 2014 г., 12:52:55 UTC+4 пользователь Andrew Truckle написал:
Thanks. Sadly I am finding all this over my head. I am also a little frustrated about how the eventual thing is going to work.

I have a C++ executable that currently calls a v2 DLL written in C#. This writes calendar events and uses the users username / password / chosen calendar.

But with this new way it is going to want to open a browser session etc. Seems very ugly to me, particularly since my routine may be called several times.

That said, when I tried making a method to connect, and then want to call it in C++, the method has a parameter IUnknown** and I don't know how to do it. All a headache to me.
On Mon, Jun 30, 2014 at 9:43 AM, Gleb Chermennov <thebitt...@gmail.com> wrote:
Just read up on OAuth and how it works, and this article seems to be a good place to start on authentication - http://nanovazquez.com/2013/01/18/working-with-google-calendar-on-dotnet/
And of course there's official docs on auth - https://developers.google.com/accounts/docs/OAuth2WebServer
Please notice that this blog post does NOT use latest NuGet packages for v3 Calendar API.

суббота, 28 июня 2014 г., 22:33:23 UTC+4 пользователь Andrew Truckle написал:
Hi

Sorry if this is a stupid question but I can't find any examples for C# about how to perform some basic tasks like:

Connecting to the calendar service.
Listing available calendars.

I can't quite get my head around all this authentification etc which was not needed in v2.

Thank you very much for any qguidance to learnign how to do this.

I have done the Google account bit with teh dash boarda nd made a project and set it to work with the calendar etc.

Thanks.

Andrew

--
You received this message because you are subscribed to a topic in the Google Groups "Google Calendar API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-calendar-api/VaLsSDqnauQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-calendar-api+unsub...@googlegroups.com.
Message has been deleted
Message has been deleted
Message has been deleted

david....@cityoforlando.net

unread,
Jun 30, 2014, 1:43:16 PM6/30/14
to google-ca...@googlegroups.com
Andrew:  This sample from Linda Lawton might help you get started.  It is not for the Calendar API, but will get you past OAuth.  You must first create a project and a Client ID for a native application (within the Google API Console), then download the JSON and use that for Linda's client_secrets.json file. It will contain all the credentials you need.

To actually add an entry to the calendar you would do something like this, where you will be using Google.Apis.Calendar.v3; and using Google.Apis.Calendar.v3.Data:

            CalendarService service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = StoredCredential,
                ApplicationName = "VacationCalendar",
            }); 
            
            Event calEvent = new Event();
            calEvent.Summary = "Test";
            calEvent.Description = "created at " + calEvent.CreatedRaw;
            EventDateTime ts = new Google.Apis.Calendar.v3.Data.EventDateTime();
            ts.Date = "2014-07-01";  // this will be an all-day event, so use ts.Date rather than ts.DateTime
            calEvent.Start = ts;
            
            EventDateTime te = new Google.Apis.Calendar.v3.Data.EventDateTime();
            te.Date = "2014-07-02";   // this will be an all-day event, so use ts.Date rather than ts.DateTime
            calEvent.End = te;

            calEvent.Location = "Arena Fonte Nova, Salvador da Bahia";
            try
            {
                service.Events.Insert(calEvent, "cityoforlando.net_9e5...@resource.calendar.google.com").Execute();
                // where the calendar ID, in this case, is pure garbage, but illustrates using a resource calendar
            }
            catch (Exception ex)
            {
                txtMessage.Text = ex.Message;

Andrew Truckle

unread,
Jun 30, 2014, 2:11:04 PM6/30/14
to google-ca...@googlegroups.com
Thanks for the help; I will investigate. I did try writing my own method for oauth but when I try to use it from my other project I get a access violation:

        public void Connect(out Int64 iResult)
        {
            m_Credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                            new ClientSecrets
                            {
                                    ClientId = "id.apps.googleusercontent.com",
                                    ClientSecret = "secret"
                            },
                            new[] {"https://www.googleapis.com/auth/calendar.readonly"},
                            "user",
                            CancellationToken.None,
                            new FileDataStore("Calendar.Auth.Store")).Result;

            iResult = MakeResult(true);

        }



--
You received this message because you are subscribed to a topic in the Google Groups "Google Calendar API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-calendar-api/VaLsSDqnauQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-calendar...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages