Hi, Thanks. I have used a sample example from google below. I authentication is appended (see bold text)
It is successful in authenticating but when i post to ITEMS_FEED = "http://www.google.com/calendar/feeds/default/owncalendars/full"; it loses it authentication. When i post to http://www.google.com/calendar/feeds/default/owncalendars/full"; does it perform some redirect ? If so how can i handle this with my java code . Thanks JAVA SAMPLE CODE public void postItem(String token) throws IOException { HttpURLConnection connection = (HttpURLConnection)(new URL(ITEMS_FEED)).openConnection(); connection.setFollowRedirects(true); // connection.setInstanceFollowRedirects(true); // System.out.println(connection.getResponseMessage()); connection.setDoInput(true); connection.setDoOutput(true); // Set the properties of the connection: the Http method, the content type // of the POST request, the authorization header and the developer key connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/atom+xml"); connection.setRequestProperty("Authorization", "GoogleLogin auth=" + token); //connection.setRequestProperty("X-Google-Key", "key=" + DEVELOPER_KEY); //connection.setRequestProperty("X-If-No-Redirect", "1"); // Post the data item OutputStream outputStream = connection.getOutputStream(); outputStream.write(DATA_ITEM.getBytes()); outputStream.close(); // Retrieve the output int responseCode = connection.getResponseCode(); Iterator i = connection.getHeaderFields().keySet().iterator(); while(i.hasNext()) System.out.println(i.next()); System.out.print(connection.getHeaderFields ().containsValue("WWW-Authenticate")); InputStream inputStream; if (responseCode == HttpURLConnection.HTTP_CREATED) { inputStream = connection.getInputStream(); } else { inputStream = connection.getErrorStream(); } // write the output to the console System.out.println(toString(inputStream)); } /** * Retrieves the authentication token for the provided set of credentials. * @return the authorization token that can be used to access authenticated * Google Base data API feeds */ public String authenticate() { // create the login request String postOutput = null; try { URL url = new URL(AUTHENTICATION_URL); postOutput = makeLoginRequest(url); } catch (IOException e) { System.out.println("Could not connect to authentication server: " + e.toString()); System.exit(1); } // Parse the result of the login request. If everything went fine, the // response will look like // HTTP/1.0 200 OK // Server: GFE/1.3 // Content-Type: text/plain // SID=DQAAAGgA...7Zg8CTN // LSID=DQAAAGsA...lk8BBbG // Auth=DQAAAGgA...dk3fA5N // so all we need to do is look for "Auth" and get the token that comes after it StringTokenizer tokenizer = new StringTokenizer(postOutput, "=\n "); String token = null; while (tokenizer.hasMoreElements()) { if (tokenizer.nextToken().equals("Auth")) { if (tokenizer.hasMoreElements()) { token = tokenizer.nextToken(); } break; } } if (token == null) { System.out.println("Authentication error. Response from server:\n" + postOutput); System.exit(1); } return token; } On 02/02/2008, Austin (Google) <[EMAIL PROTECTED]> wrote: > > Hi, > After you obtained the auth token, you are supposed to use it by embedding > it within the http request header for every request. For more details on > how this is done, please read - > > http://code.google.com/apis/gdata/auth.html > > Hope it helps, > Austin > > On Feb 1, 2008 1:25 PM, marco <[EMAIL PROTECTED]> wrote: > > > > > I am trying to create a new event using java using the following > > method specified in > > http://code.google.com/apis/calendar/developers_guide_protocol.html#CreatingCalendars > > on Creating new calenders. > > > > I am able to login and authenticate properly but when i POST to the > > feed > > > > ITEMS_FEED = "http://www.google.com/calendar/feeds/default/ > > owncalendars/full<http://www.google.com/calendar/feeds/default/owncalendars/full> > > "; > > > > > > > > The response i am getting is > > > > Obtained authorization token: > > DQAAAHYAAABvDVTChTtZtQ4EpQ202pJCG5w4yJHIiJN5-nKn- > > sMPJ5X_Wk169vKqvG7plP5yTzuwjQRVo7RYGySjl92FVT8im1eDNEKN7sprgdbBbzq8V- > > hxjVJjkXVEkWwc-Gog2izbUDMNWSqHf-i-Vr1v2YftnIORHgkf3Cah0IJKue4xjQ > > <HTML> > > <HEAD> > > <TITLE>Authorization required</TITLE> > > </HEAD> > > <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> > > <H1>Authorization required</H1> > > <H2>Error 401</H2> > > </BODY> > > </HTML> > > > > > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
