Thanks for reply...

STEP 1
String clientId = "xxxxxxxxxxx";
String callback = "http://"; + request.getServerName() + ":" + 
request.getServerPort() + request.getContextPath() + "/myUrl.jsp";   
String authUrl = "https://accounts.google.com/o/oauth2/auth?client_id="; + 
clientId + "&redirect_uri=" + callback + 
"&scope=https://www.google.com/m8/feeds/&response_type=code";;
response.sendRedirect(authUrl);    

STEP 2 (myUrl.jsp)
String code = request.getParameter("code");
String clientSecret = "yyyyyyyyyyyyyyyyyyyyy";
String newUrl = "https://accounts.google.com/o/oauth2/token";;
String clientId = "xxxxxxxxxxxxxxxxxxxxxxxxx";
String callback = "http://"; + request.getServerName() + ":" + 
request.getServerPort() + request.getContextPath() + "/protectedUrl2.jsp";

String requestUrl = "https://accounts.google.com/o/oauth2/auth?client_id=";
            + clientId
            + "&redirect_uri="
            + callback
            + "&scope=https://www.google.com/m8/feeds/&response_type=";;

String tokenUrl = new String( "https://accounts.google.com/o/oauth2/token";);
    
    StringBuffer params = new StringBuffer("");
    params.append("code=" + code);
    params.append("&client_id=" + clientId);
    params.append("&client_secret=" + clientSecret);
    params.append("&redirect_uri=" + callback);
    params.append("&grant_type=authorization_code");

    try 
    {
        // Send data
        URL url = new URL(tokenUrl.toString());
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new 
OutputStreamWriter(conn.getOutputStream());
        wr.write(params.toString());
        wr.flush();

        // Get the response
        BufferedReader rd = new BufferedReader(new 
InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) 
        {
            System.out.println("---" + line);
        }
        wr.close();
        rd.close();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }


When myUrl.jsp start, I get this error:


java.io.IOException: Server returned HTTP response code: 400 for URL: 
https://accounts.google.com/o/oauth2/token
    at 
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1313)
    at 
sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
    at 
org.apache.jsp.protectedUrl_jsp._jspService(protectedUrl_jsp.java:108)
    at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at 
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:386)
    at 
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313)
    at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
    at 
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at 
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at 
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at 
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at 
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at 
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at 
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at 
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
    at 
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:859)
    at 
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
    at 
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
    at java.lang.Thread.run(Thread.java:619)


Help me please!

Thanks

-- 
You received this message because you are subscribed to the Google
Groups "Google Contacts, Shared Contacts and User Profiles APIs" 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://code.google.com/apis/contacts/community/forum.html

Reply via email to