Re: Sign to Google with Java Wicket
Hi, This is no more a question about Wicket. Please use StackOverflow or any other appropriate forum. A hint: Desktop.getDesktop().browse(new URI("http://www.gmail.com";)); starts a new session that knows nothing about the one that made the handshake. On Sun, Nov 24, 2013 at 11:25 PM, MartinoSuperman wrote: > Hi, > > Thanks for your help. > > I tried it in 2 ways: > > Here are the codes: > > 1. > > public class GoogleClientLogin { > > /** > * @param args the command line arguments > */ > public static void main(String[] args) throws IOException, > URISyntaxException { > //Open the Connection > URL url = new URL("https://www.google.com/accounts/ClientLogin";); > > HttpURLConnection urlConnection = (HttpURLConnection) > url.openConnection(); > urlConnection.setRequestMethod("POST"); > urlConnection.setDoInput(true); > urlConnection.setDoOutput(true); > urlConnection.setUseCaches(false); > urlConnection.setRequestProperty("Content-Type", > "application/x-www-form-urlencoded"); > > // Form the POST parameters > StringBuilder content = new StringBuilder(); > content.append("Email=").append(URLEncoder.encode("m...@gmail.com > ", > "UTF-8")); > content.append("&Passwd=").append(URLEncoder.encode("password", > "UTF-8")); > //content.append("&service=").append(URLEncoder.encode(yourapp, > "UTF-8")); > OutputStream outputStream = urlConnection.getOutputStream(); > outputStream.write(content.toString().getBytes("UTF-8")); > outputStream.close(); > > // Retrieve the output > int responseCode = urlConnection.getResponseCode(); > InputStream inputStream; > if (responseCode == HttpURLConnection.HTTP_OK) { > inputStream = urlConnection.getInputStream(); > if(Desktop.isDesktopSupported()) > { > Desktop.getDesktop().browse(new URI("http://www.gmail.com";)); > } > System.out.println("Connection is OK"); > } else { > inputStream = urlConnection.getErrorStream(); > System.out.println("Connection is not OK"); > } > } > } > > 2. > public class BigQuerySample { > public static void main(String[] args) throws IOException, > URISyntaxException { > HttpTransport transport = GoogleTransport.create(); > transport.addParser(new JsonCParser()); > try { > // authenticate with ClientLogin > ClientLogin authenticator = new ClientLogin(); > authenticator.authTokenType = "ndev"; > authenticator.username = "mail"; > authenticator.password = "password"; > authenticator.authenticate().setAuthorizationHeader(transport); > > if(Desktop.isDesktopSupported()) > { > Desktop.getDesktop().browse(new URI("http://www.gmail.com";)); > } > //authenticator. > > //openWebpage(new URL("www.google.com")); > > // make query request > /* HttpRequest request = transport.buildGetRequest(); > request.setUrl("https://www.googleapis.com/bigquery/v1/query";); > request.url.put( > "q", "select count(*) from [bigquery/samples/shakespeare];"); > System.out.println(request.execute().parseAsString());*/ > } catch (HttpResponseException e) { > System.err.println(e.response.parseAsString()); > throw e; > } > } > > As you can see, directly, when a connection is made to Google account and > when signing in succeeds, I am opening a page of gmail in a new browser > page. But when the page opens, gmail is not opened. > > What am I doing wrong here? In both cases, it is said that the connection > was established. > > > > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Sign-to-Google-with-Java-Wicket-tp4662591p4662634.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Re: Sign to Google with Java Wicket
Hi, Thanks for your help. I tried it in 2 ways: Here are the codes: 1. public class GoogleClientLogin { /** * @param args the command line arguments */ public static void main(String[] args) throws IOException, URISyntaxException { //Open the Connection URL url = new URL("https://www.google.com/accounts/ClientLogin";); HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("POST"); urlConnection.setDoInput(true); urlConnection.setDoOutput(true); urlConnection.setUseCaches(false); urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Form the POST parameters StringBuilder content = new StringBuilder(); content.append("Email=").append(URLEncoder.encode("m...@gmail.com", "UTF-8")); content.append("&Passwd=").append(URLEncoder.encode("password", "UTF-8")); //content.append("&service=").append(URLEncoder.encode(yourapp, "UTF-8")); OutputStream outputStream = urlConnection.getOutputStream(); outputStream.write(content.toString().getBytes("UTF-8")); outputStream.close(); // Retrieve the output int responseCode = urlConnection.getResponseCode(); InputStream inputStream; if (responseCode == HttpURLConnection.HTTP_OK) { inputStream = urlConnection.getInputStream(); if(Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI("http://www.gmail.com";)); } System.out.println("Connection is OK"); } else { inputStream = urlConnection.getErrorStream(); System.out.println("Connection is not OK"); } } } 2. public class BigQuerySample { public static void main(String[] args) throws IOException, URISyntaxException { HttpTransport transport = GoogleTransport.create(); transport.addParser(new JsonCParser()); try { // authenticate with ClientLogin ClientLogin authenticator = new ClientLogin(); authenticator.authTokenType = "ndev"; authenticator.username = "mail"; authenticator.password = "password"; authenticator.authenticate().setAuthorizationHeader(transport); if(Desktop.isDesktopSupported()) { Desktop.getDesktop().browse(new URI("http://www.gmail.com";)); } //authenticator. //openWebpage(new URL("www.google.com")); // make query request /* HttpRequest request = transport.buildGetRequest(); request.setUrl("https://www.googleapis.com/bigquery/v1/query";); request.url.put( "q", "select count(*) from [bigquery/samples/shakespeare];"); System.out.println(request.execute().parseAsString());*/ } catch (HttpResponseException e) { System.err.println(e.response.parseAsString()); throw e; } } As you can see, directly, when a connection is made to Google account and when signing in succeeds, I am opening a page of gmail in a new browser page. But when the page opens, gmail is not opened. What am I doing wrong here? In both cases, it is said that the connection was established. -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Sign-to-Google-with-Java-Wicket-tp4662591p4662634.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org
Re: Sign to Google with Java Wicket
Hi, You can check Planning Poker<https://github.com/vonZeppelin/planning-poker/blob/master/pom.xml#L117> application. It uses Buji-OAuth library to login to Google. I have used https://github.com/fernandezpablo85/scribe-java for implementing OAuth authorization before. It works well for many OAuth providers but the author (and many other people involved in OAuth development) thinks that Google's implementation of OAuth(2) is not following the specs and he refuses to add impl for it. There are code samples for Google OAuth in the closed tickets in the project. On Thu, Nov 21, 2013 at 3:49 PM, MartinoSuperman wrote: > Hi, > > Does someone know how to open a Google account in Java (Wicket) and how to > close it again? > > I read several pages about it on the internet, but I cannot figure it out. > > I accomplished to open a connection to GoogleMail, after which a mail is > being sent via the SMTP server of Google. > > Now, I only want an automatic login in Java. When I have finished it has to > log out again. > > Can someone help me? > > > > -- > View this message in context: > http://apache-wicket.1842946.n4.nabble.com/Sign-to-Google-with-Java-Wicket-tp4662591.html > Sent from the Users forum mailing list archive at Nabble.com. > > - > To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org > For additional commands, e-mail: users-h...@wicket.apache.org > >
Sign to Google with Java Wicket
Hi, Does someone know how to open a Google account in Java (Wicket) and how to close it again? I read several pages about it on the internet, but I cannot figure it out. I accomplished to open a connection to GoogleMail, after which a mail is being sent via the SMTP server of Google. Now, I only want an automatic login in Java. When I have finished it has to log out again. Can someone help me? -- View this message in context: http://apache-wicket.1842946.n4.nabble.com/Sign-to-Google-with-Java-Wicket-tp4662591.html Sent from the Users forum mailing list archive at Nabble.com. - To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org For additional commands, e-mail: users-h...@wicket.apache.org