Google 日历 API - 未从 Execute() C# 返回

Google Calendar API - Not Returning From Execute() C#

运行 下面的代码从不 returns 来自 Execute 函数。我与 developer.gserviceaccount.com 帐户共享的个人 gmail 帐户上有一个私人日历。

看API管理器,usage/quotes显示我用过甚至打过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();        
    }    
}

我仍然 运行 关注这个问题。我创建了一个简单的应用程序来重现这个,有人有什么想法吗?保管箱.com/s/g45xcta7ii3hj51/GoogleTestWeb.zip?dl=0

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

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

我不确定你为什么要获取日历列表。我个人认为您应该使用 Calendars: get 您已经从 google 日历网站知道日历的 ID。

提示:执行将要return一个我不确定的对象.ToString()在它上面确实是最好的主意。

更新码:

/// <summary>
        /// Returns metadata for a calendar. 
        /// Documentation:https://developers.google.com/google-apps/calendar/v3/reference/calendars/get
        /// </summary>
        /// <param name="service">Valid Autenticated Calendar service</param>
        /// <param name="id">Calendar identifier.</param>
        /// <returns>Calendar resorce: https://developers.google.com/google-apps/calendar/v3/reference/calendars#resource </returns>
        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

上的示例项目中的代码

此问题在 https://github.com/google/google-api-dotnet-client/issues/606. It seems that we currently have a bug in 1.9.3, which is fixed in the github repository (The fix itself is in 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 包可用,阅读更多信息:http://google-api-dotnet-client.blogspot.com/2015/12/announcing-release-of-1100.html