Google Calendar API – 不从Execute()返回C#

运行下面的代码永远不会从Execute函数返回。 我在个人Gmail帐户上有一个私人日历,我与developer.gserviceaccount.com帐户共享。

查看API管理器,使用/引用显示我已经使用过甚至命中过api。

任何想法都赞赏。

using System.Security.Cryptography.X509Certificates; using System.Web; using Google.Apis.Calendar.v3; using Google.Apis.Auth.OAuth2; using Google.Apis.Services; public class GoogleLoginWithServiceAccount { public string getEventList() { var GoogleOAuth2CertificatePath = HttpContext.Current.Server.MapPath("~/xx/xx.p12"); var GoogleOAuth2EmailAddress = "xx-xxxx@developer.gserviceaccount.com"; var GoogleOAuth2PrivateKey = "notasecret"; var certificate = new X509Certificate2(GoogleOAuth2CertificatePath, GoogleOAuth2PrivateKey, X509KeyStorageFlags.Exportable); var credential = new ServiceAccountCredential( new ServiceAccountCredential.Initializer(GoogleOAuth2EmailAddress) { //User = GoogleAccount, Scopes = new string[] { CalendarService.Scope.Calendar } }.FromCertificate(certificate)); // Create the service. var service = new CalendarService(new BaseClientService.Initializer() { HttpClientInitializer = credential, ApplicationName = "Testing" }); var listRequest = service.CalendarList.List(); return listRequest.Execute().ToString(); } } 

我还在遇到这个问题。 我已经创建了一个简单的应用程序来重现这一点,任何人都有任何想法? dropbox.com/s/g45xcta7ii3hj51/GoogleTestWeb.zip?dl=0

https://github.com/google/google-api-dotnet-client/issues/606中详细介绍了此问题。 看来我们目前在1.9.3中有一个错误,该错误已在github存储库中修复(修复本身位于https://github.com/google/google-api-dotnet-client/pull/612 )。

计划在未来几周推出新版本,敬请关注; http://google-api-dotnet-client.blogspot.com/

如果您想要自己玩和测试,可以使用GitHub中的项目和日历服务。 您最好从https://developers.google.com/resources/api-libraries/download/calendar/v3/csharp下载日历服务,以避免绑定重定向。 我在#606中解释了你要做的事情。

更新(12月15日):可以获得1.10.0的新NuGet包,请阅读以下url了解更多信息: http : //google-api-dotnet-client.blogspot.com/2015/12/announcing-release-of-1100。 HTML

日历和日历之间存在差异。 在Google日历网站中,日历表左侧显示日历列表。 但是,要在calendarlist上显示日历,必须将其添加到日历表中。

您为服务帐户授予了对日历的访问权限,但是您是否以编程方式告诉它将日历添加到其日历表中? 你应该使用CalendarList:insert

我不确定你为什么要得到日历。 我个人认为你应该使用日历:让你已经知道谷歌日历网站上的日历ID。

提示: Execute将返回一个我不确定的对象.ToString()就是最好的主意。

更新代码:

 ///  /// Returns metadata for a calendar. /// Documentation:https://developers.google.com/google-apps/calendar/v3/reference/calendars/get ///  /// Valid Autenticated Calendar service /// Calendar identifier. /// Calendar resorce: https://developers.google.com/google-apps/calendar/v3/reference/calendars#resource  public static Calendar get(CalendarService service, string id) { try { return service.Calendars.Get(id).Execute(); } catch (Exception ex) { Console.WriteLine(ex.Message); return null; } } 

我在GitHub上的示例项目中的代码

在此处输入图像描述