tags:

views:

53

answers:

1

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

+2  A: 

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).

thekaido
ok thanks this works, but do you know how to update entries? Can't get it to work.
Niels Bosma