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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With