【问题标题】:Universal Windows Platform App with google calendar带有谷歌日历的通用 Windows 平台应用程序
【发布时间】:2017-03-24 04:32:08
【问题描述】:

嘿,我正在尝试制作一个包含谷歌日历的通用 Windows 平台应用程序,但我不知道如何转换代码,我得到了在 WPF 应用程序上工作的代码。 我不是最擅长编码https://developers.google.com/google-apps/calendar/quickstart/dotnet 这是我在开始时用作指导的网站,如果它有任何帮助,有帮助吗? 代码如下:

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 });


                }
            }
        }
    }
}

【问题讨论】:

  • “转换代码”?在您发布的示例中,我没有看到任何特定于 WPF 或 UWP 的内容。你有什么问题,确实
  • 我的问题是 GetFolderPath、SpecialFolder 和 FileDataStore 在 UWP 中不可用
  • 您将希望使用 UWP 文件系统 API,请参阅此处:stackoverflow.com/questions/33082835/…
  • 据我所知,客户端库不支持 UWP。

标签: c# win-universal-app google-calendar-api google-api-dotnet-client


【解决方案1】:

目前 Google .net 客户端库不支持 UWP。

来自client library (supported platform list)的链接

chrisdunelm 27 天前 Google 会员 很遗憾我们不支持 UWP 还没有,所以还不能上榜。也许我们应该强调 我们不支持它:(

更新:

我们计划在 v2.0 版本中支持 UWP,我们希望在 2017 年初发布。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-03-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多