Hello Luca, Why did you create an other thread for the same topic? I already replied in the other one.
Best, Alain On Thu, Jun 16, 2011 at 12:12 PM, Luca Santaniello < [email protected]> wrote: > Hi all, > > I need invocate google to get information account for my web site. I > invocate OAuth 2.0 but I don't understand very well. > > I user 2 method: > > Method 1... Step 1 and 2 > Step 1 > String next = "http://www.example.com/welcome.html"; > String scope = "https://www.google.com/m8/feeds/"; > boolean secure = false; > boolean session = true; > String authSubLogin = AuthSubUtil.getRequestUrl(next, scope, secure, > session); > > It's OK > > Step 2 > String token = request.getParameter("token"); > > I get token!!! but then how I can get user information? Where I use my > secret id and password? > > Method 2... Step 1 and 2 > 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() + "/myUrl.jsp"; > > 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(); > } > > and then? How I can get User information? > > Which is right version? Method 1 or 2? > > Can you help me? > > Please > > Thanks in advance > > -- > 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 > -- Alain Vongsouvanh -- 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
