You can copy class
AuthorizationCodeInstalledApp
and override the method
browse (String url)
You need to understand, go to the url programmatically, like this (I use htmlunit):
public void browse(String url) throws IOException { WebClient webClient = initWebClient(); HtmlPage htmlPage = webClient.getPage(url); //first you need login with your email and password final HtmlTextInput login = (HtmlTextInput) htmlPage.getByXPath("//input[@type='email']").get(0); final HtmlPasswordInput pass = (HtmlPasswordInput) htmlPage.getByXPath("//input[@type='password']").get(0); HtmlSubmitInput button = (HtmlSubmitInput) htmlPage.getByXPath("//input[@type='submit']").get(0); //set input login and passwd login.setText(this.login); pass.setText(this.passwd); //press submit button button.click(); //next need select account htmlPage = webClient.getPage(url); DomNodeList<HtmlElement> list = htmlPage.getElementById("account-list").getElementsByTagName("li"); String account = list.get(0).getElementsByTagName("a").get(0).getAttribute("href"); System.out.println(account); htmlPage = webClient.getPage(account); //and click submit button for approve System.out.println("Wait 10sec."); webClient.waitForBackgroundJavaScript(10000); HtmlButton submitInput = (HtmlButton) htmlPage.getElementById("submit_approve_access"); submitInput.click(); }
This works great for me.
source share