2

Hey im trying to make an Universal Windows Platform App where google calendar is in it, but i cant figure out how to convert the code, i got the code to work on a WPF App. I am not the best at coding https://developers.google.com/google-apps/calendar/quickstart/dotnet this is the site i use as a guideline in the start if its to any help, any help? Code below:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Google.Apis.Auth.OAuth2;
using Google.Apis.Calendar.v3;
using Google.Apis.Calendar.v3.Data;
using Google.Apis.Services;
using Google.Apis.Util.Store;

namespace Test1UWA
{
    class GoogleEvents4
    {
        public string Title { get; set; }
        public DateTime? StartDate { get; set; }
        public DateTime? EndDate { get; set; }
    }

    class GoogleClass4
    {
        public List<GoogleEvents4> GoogleEvents = new List<GoogleEvents4>();

        static string[] Scopes = { CalendarService.Scope.CalendarReadonly };
        static string ApplicationName = "Google Calendar API .NET Quickstart";



        public GoogleClass4()
        {
            UserCredential credential;

            using (var stream =
                            new FileStream("client_secret4.json", FileMode.Open, FileAccess.Read))
            {
                string credPath = System.Environment.GetFolderPath(
                    System.Environment.SpecialFolder.Personal);
                credPath = Path.Combine(credPath, ".credentials/calendar-dotnet-quickstart.json");

                credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
                    GoogleClientSecrets.Load(stream).Secrets,
                    Scopes,
                    "user",
                    CancellationToken.None,
                    new FileDataStore(credPath, true)).Result;

            }
            // Create Google Calendar API service.
            var service = new CalendarService(new BaseClientService.Initializer()
            {
                HttpClientInitializer = credential,
                ApplicationName = ApplicationName,
            });

            // Define parameters of request.
            EventsResource.ListRequest request = service.Events.List("primary");
            request.TimeMin = DateTime.Now;
            request.ShowDeleted = true;
            request.SingleEvents = true;
            request.MaxResults = 10;
            request.OrderBy = EventsResource.ListRequest.OrderByEnum.StartTime;

            // List events.
            Events events = request.Execute();
            if (events.Items != null && events.Items.Count > 0)
            {
                foreach (var eventItem in events.Items)
                {
                    string when = eventItem.Start.DateTime.ToString();
                    if (String.IsNullOrEmpty(when))
                    {
                        when = eventItem.Start.Date;
                    }

                    GoogleEvents.Add(new GoogleEvents4 { Title = eventItem.Summary, StartDate = eventItem.Start.DateTime, EndDate = eventItem.End.DateTime });


                }
            }
        }
    }
}

1 Answers1

1

At this time the Google .net Client library does not support UWP.

Link from the client library (supported platform list)

chrisdunelm 27 days ago Google member Unfortunately we don't support UWP yet, so it can't be on the list yet. Maybe we should highlight that we don't support it :(

Update:

We plan to support UWP in the v2.0 release, which we hope will be early 2017.

Linda Lawton - DaImTo
  • 106,405
  • 32
  • 180
  • 449