【发布时间】: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