从 Google Apps 帐户访问 GData Calender?

发布于 2024-09-29 02:46:43 字数 759 浏览 4 评论 0原文

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

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

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

How do you get this to work with Google Apps?对于 Google 应用程序,我还必须使用任何其他类型的身份验证吗?


更新:

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

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

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

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

I'm building a simple app too that needs to access a calendar that's in my Google Apps account. But I'm having problems with authentication. I've tried the following code but it doesn't work:

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

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

How do you get this to work with Google Apps? Is there any other type of authentication that I have to use for Google apps?


Update:

Unlocking the captcha solved my problem with getting the feed. Now I've hit the next wall: updating an event.

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

Gives me the GDataRequestException exception: "Can not update a read-only entry".

Im using the private calendar xml address that I got under kalendarsettings:
https://www.google.com/calendar/feeds/_%40group.calendar.google.com/private-/basic

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱殇璃 2024-10-06 02:46:43

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

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 也对 @ 符号进行编码)。

I would recommend using Fiddler to see what http response you are getting back from Google. When I ran your code against my google apps account, I was getting back an "Error=CaptchaRequired" response. This required that I go to https://www.google.com/a/yourgoogleappdomain.com/UnlockCaptcha (replacing with your domain obviously). After I did that I was able to properly connect. You may be getting a different error code too so check for that and post it here. You could have an invalid password or invalid url or this functionality is disabled by your google apps administrator. Here is my sample code:

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

Make sure to replace the email, password, and email inside of the URL (url encode the @ sign too).

貪欢 2024-10-06 02:46:43
    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;
        }
    }
    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;
        }
    }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文