【问题标题】:Accessing GData Calender from Google Apps account?从 Google Apps 帐户访问数据日历?
【发布时间】:2011-04-29 15:01:41
【问题描述】:

我也在构建一个简单的应用程序,它需要访问我的 Google Apps 帐户中的日历。但是我遇到了身份验证问题。我已经尝试了以下代码,但它不起作用:

 Service service = new Service("<appname>");
 service.setUserCredentials("<email>", "<password>");

 CalendarEntry entry = (CalendarEntry)service.Get("<eventUrl>");

如何让它与 Google Apps 一起使用?我必须对 Google 应用使用任何其他类型的身份验证吗?


更新:

解锁验证码解决了我获取提要的问题。现在我碰到了下一堵墙:更新事件。

entry.Title.Text = "Foo";
entry.Update();

给我 GDataRequestException 异常:“无法更新只读条目”。

我正在使用我在 kalendarsettings 下获得的私人日历 xml 地址: https://www.google.com/calendar/feeds/_%40group.calendar.google.com/private-/basic

【问题讨论】:

  • 对于更新,请尝试将 /basic 提要更改为 /full,然后重新尝试更新 - 因为该代码对我有用。

标签: c# gdata-api


【解决方案1】:

我建议您使用Fiddler 查看您从 Google 收到的 http 响应。当我针对我的 google 应用程序帐户运行您的代码时,我收到了“Error=CaptchaRequired”响应。这要求我去https://www.google.com/a/yourgoogleappdomain.com/UnlockCaptcha(显然替换为您的域)。在我这样做之后,我能够正确连接。您也可能会收到不同的错误代码,因此请检查并在此处发布。您的密码或网址可能无效,或者您的谷歌应用管理员禁用了此功能。这是我的示例代码:

var calendarService = new CalendarService("company-app-version");
calendarService.setUserCredentials("<email>", "<password>");
var eventQuery = new EventQuery("http://www.google.com/calendar/feeds/user%40domain.com/private/full");
var eventFeed = calendarService.Query(eventQuery);
foreach (var atomEntry in eventFeed.Entries)
{
    Console.WriteLine(atomEntry.Title.Text);
}

确保替换 URL 中的电子邮件、密码和电子邮件(url 也编码 @ 符号)。

【讨论】:

  • 好的,谢谢这个,但是你知道如何更新条目吗?无法让它工作。
【解决方案2】:
    using Google.GData.Client;
    public bool ValidateGoogleAccount(string login, string password)
    {
        try
        {
            Service bloggerService = new Service("blogger", "App-Name");
            bloggerService.Credentials = new GDataCredentials(login, password);
            string token = bloggerService.QueryAuthenticationToken();

            if (token != null)
                return true;
            else
                return false;
        }
        catch (Google.GData.Client.InvalidCredentialsException)
        {
            return false;
        }
    }

【讨论】:

    【解决方案3】:

    来自谷歌的 Austin 提供的另一个解决方案(它对我有用): http://groups.google.com/group/google-calendar-help-dataapi/browse_thread/thread/400104713435a4b4?pli=1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多