Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

upload video to youtube without signing-in in the browser

i built java application on desktop that allows sharing video to youtube to specific google acount. I used the suggested code from example for uploading a video from: https://developers.google.com/youtube/v3/code_samples/java#upload_a_video

with the json token of the user. But when i'm trying to upload it opens a web page of google and askes me to log-in and approve uploading videos with my user.

Is there a way to skip this level and do it from the java code? I don't want to make the user log-in in a web page to his google acount and only use the GUI i made with java.

like image 625
nat Avatar asked Sep 29 '22 22:09

nat


1 Answers

You can copy class

AuthorizationCodeInstalledApp

and override the method

browse(String url)

You need to realize, go to a 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();
}

that's fine works for me.

like image 109
mindw0rk Avatar answered Oct 05 '22 07:10

mindw0rk