Hello everybody,
I'm trying to use Google Calendar in Java Code. Strangely, this code
doesn't work, and I've been looking at it for hours and I just can't
figure out where the problem is. Maybe you could please help me.
I always get this error: Exception in thread "main"
com.meterware.httpunit.AuthorizationRequiredException: GoogleLogin
authentication required: {service="cl", realm="https://www.google.com/
accounts/ClientLogin"}.
But the header is sent, right? And I really looked at every character
a 100 times. Where is the problem?
Thank you in advance.
--------------
import com.meterware.httpunit.*;
public class calendar {
public static void main(String[] args) throws Exception {
String username = "USERNAME";
String password = "PASSWORD";
String address = "http://www.google.com/calendar/feeds/default/
allcalendars/full";
WebConversation wc = new WebConversation();
PostMethodWebRequest authReq = new PostMethodWebRequest(
"https://
www.google.com/accounts/ClientLogin" );
authReq.setParameter("accountType", "GOOGLE");
authReq.setParameter( "Email", username );
authReq.setParameter( "Passwd", password );
authReq.setParameter( "service", "cl" );
WebResponse resp = wc.getResponse(authReq);
if (resp.getResponseCode() == 200) {
String xmlSource = resp.getText();
String authCookie =
xmlSource.substring(xmlSource.indexOf("Auth=")
+ 5).trim();
wc = new WebConversation();
WebRequest calReq = new GetMethodWebRequest(address);
calReq.setHeaderField("Authorization: GoogleLogin
auth=",
authCookie);
calReq.setHeaderField("Content-Type",
"application/x-www-form-
urlencoded");
WebResponse response = wc.getResponse(calReq);
String xmlSources = response.getText();
System.out.println(xmlSources);
}
}
}
--------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Calendar Data API" group.
To post to this group, send email to
[email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/google-calendar-help-dataapi?hl=en
-~----------~----~----~----~------~----~------~--~---