2

嘿即時嘗試使通用Windows平臺應用程序谷歌日曆是在其中,但我無法弄清楚如何轉換代碼,我得到的代碼工作在WPF應用程序。 我不是最好的編碼https://developers.google.com/google-apps/calendar/quickstart/dotnet這是我用作開始的指南如果它的任何幫助,任何幫助? 以下代碼:谷歌日曆通用Windows平臺應用程序

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


       } 
      } 
     } 
    } 
} 
+0

「轉換代碼」?我沒有在您發佈的示例中看到任何WPF或UWP特定的問題。您有什麼問題,*完全*? – Dai

+0

我的問題是GetFolderPath,SpecialFolder和FileDataStore在UWP中不可用 –

+0

您將要使用UWP Filesyst電子API代替,看到這裏:http://stackoverflow.com/questions/33082835/windows-10-universal-app-file-directory-access – Dai

回答

1

此時Google.net客戶端庫不支持UWP。從client library (supported platform list)

chrisdunelm 11天以前谷歌成員

鏈接不幸的是,我們不支持 UWP還,所以它不能在名單上呢。也許我們應該強調 ,我們不支持它:(

更新:

我們計劃支持UWP在V2.0版本中,我們希望這將是2017年年初

相關問題