首页 > 解决方案 > 如何自动打开浏览器进行用户授权(“/回调”)?

问题描述

我正在尝试将一些视频从我的 java 服务器上传到 youtube,但我对数据授权过程有些困惑。我阅读了很多关于它的文档我无法成功地自动向用户显示授权窗口,而不是那样,我在(服务器的)控制台中收到一条消息“请在浏览器中打开以下地址:”。我必须点击它,这样用户才能看到授权窗口。

 https://accounts.google.com/o/oauth2/auth?client_id=975725361259-m2pmvjv9uobcpq03tja9i66dtot7lkjv.apps.googleusercontent.com&redirect_uri=http://localhost:8081/Callback&response_type=code&scope=https://www.googleapis.com/auth/youtube.upload

我想我在这里遗漏了一些东西..

GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets,   scopes).setCredentialDataStore(datastore)
            .build();

    // Build the local server and bind it to port 8081
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8081).build();

我该如何解决它,以便用户可以自动重定向到应用程序(localhost)中的该窗口?

我错过了什么?

谢谢!

标签: javaspring-bootyoutube-apigoogle-oauthgoogle-api-java-client

解决方案


推荐阅读