具有 google 日历的通用 Windows 平台应用程序
Universal Windows Platform App with google calendar
嘿,我正在尝试制作一个通用 Windows 平台应用程序,其中包含 google 日历,但我不知道如何转换代码,我得到了可以在 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 });
}
}
}
}
}
此时 Google .net 客户端库不支持 UWP。
Link 来自 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 :(
更新:
We plan to support UWP in the v2.0 release, which we hope will be early 2017.
嘿,我正在尝试制作一个通用 Windows 平台应用程序,其中包含 google 日历,但我不知道如何转换代码,我得到了可以在 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 });
}
}
}
}
}
此时 Google .net 客户端库不支持 UWP。
Link 来自 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 :(
更新:
We plan to support UWP in the v2.0 release, which we hope will be early 2017.