【问题标题】:Youtube Data API v3 oAuth2 failing to change permissionsYoutube Data API v3 oAuth2 无法更改权限
【发布时间】:2015-12-09 08:06:26
【问题描述】:

我正在使用 google 的 api 创建一个小型桌面应用程序,以使上传视频更易于管理(我管理一个网络集线器频道,关于我为什么需要它的长篇故事)。我已经按照 google 的指南获得了一个起点,但是使用 oauth2 的身份验证失败并显示以下控制台输出:

    Sep 12, 2015 9:43:29 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for everybody: C:\Users\BossLetsPlays\.oauth-credentials
Sep 12, 2015 9:43:29 PM com.google.api.client.util.store.FileDataStoreFactory setPermissionsToOwnerOnly
WARNING: unable to change permissions for owner: C:\Users\BossLetsPlays\.oauth-credentials
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
java.io.IOException: java.net.BindException: Address already in use: JVM_Bind
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:107)
    at com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp.authorize(AuthorizationCodeInstalledApp.java:76)
    at com.bossletsplays.ytclient.utils.AuthUtil.authorize(AuthUtil.java:67)
    at com.bossletsplays.ytclient.utils.VideoUploader.upload(VideoUploader.java:48)
    at com.bossletsplays.ytclient.gui.MainGui$4.actionPerformed(MainGui.java:152)
    at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    at java.awt.Component.processMouseEvent(Unknown Source)
    at javax.swing.JComponent.processMouseEvent(Unknown Source)
    at java.awt.Component.processEvent(Unknown Source)
    at java.awt.Container.processEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Window.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$500(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPrivilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)
Caused by: java.net.BindException: Address already in use: JVM_Bind
    at java.net.DualStackPlainSocketImpl.bind0(Native Method)
    at java.net.DualStackPlainSocketImpl.socketBind(Unknown Source)
    at java.net.AbstractPlainSocketImpl.bind(Unknown Source)
    at java.net.PlainSocketImpl.bind(Unknown Source)
    at java.net.ServerSocket.bind(Unknown Source)
    at java.net.ServerSocket.<init>(Unknown Source)
    at org.mortbay.jetty.bio.SocketConnector.newServerSocket(SocketConnector.java:80)
    at org.mortbay.jetty.bio.SocketConnector.open(SocketConnector.java:73)
    at org.mortbay.jetty.AbstractConnector.doStart(AbstractConnector.java:283)
    at org.mortbay.jetty.bio.SocketConnector.doStart(SocketConnector.java:147)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at org.mortbay.jetty.Server.doStart(Server.java:235)
    at org.mortbay.component.AbstractLifeCycle.start(AbstractLifeCycle.java:50)
    at com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver.getRedirectUri(LocalServerReceiver.java:104)
    ... 40 more

我在网上很多地方都看到过这个问题,但没有有效的解决方案。谷歌说这个错误是通过抛出警告而不是 IOExceptions 来修复的,但我仍然得到警告和 IOExceptions。

这是处理身份验证的代码:

public static final HttpTransport HTTP_TRANSPORT        = new NetHttpTransport();
public static final JsonFactory   JSON_FACTORY          = new JacksonFactory();
private static final String       CREDENTIALS_DIRECTORY = ".oauth-credentials";

public static Credential authorize(List<String> scopes, String credentialDatastore) throws IOException {
    Reader clientSecretReader = new InputStreamReader(AuthUtil.class.getResourceAsStream("/client_secrets.json"));
    GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, clientSecretReader);
    System.out.println(clientSecrets.getDetails().getClientId());
    if (clientSecrets.getDetails().getClientId().startsWith("Enter")
            || clientSecrets.getDetails().getClientSecret().startsWith("Enter ")) {
        System.out.println(
                "Enter Client ID and Secret from https://code.google.com/apis/console/?api=youtube"
                        + "into src/main/resources/client_secrets.json");
        System.exit(1);
    }
    FileDataStoreFactory fileDataStoreFactory = new FileDataStoreFactory(
            new File(System.getProperty("user.home") + "/" + CREDENTIALS_DIRECTORY));
    DataStore<StoredCredential> datastore = fileDataStoreFactory.getDataStore(credentialDatastore);
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
            HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, scopes).setCredentialDataStore(datastore)
                    .build();
    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();

    return new AuthorizationCodeInstalledApp(flow, localReceiver).authorize("user");
}

是的,我已经替换了文件中的客户端 ID 和机密。

【问题讨论】:

    标签: youtube oauth-2.0 youtube-api authorization google-oauth


    【解决方案1】:

    问题出现在行:

    LocalServerReceiver localReceiver = new LocalServerReceiver.Builder().setPort(8080).build();
    

    可能是 8080 端口被另一个进程使用...

    确保运行命令:

    netstat -an | grep 8080
    

    然后搜索进程并杀死它

    【讨论】:

    • 谢谢!原来apache xamp正在使用该端口...将本地接收器的端口切换为1043,现在一切正常
    猜你喜欢
    • 2014-11-19
    • 1970-01-01
    • 1970-01-01
    • 2013-10-24
    • 1970-01-01
    • 2015-10-05
    • 1970-01-01
    • 2012-12-19
    • 2021-05-19
    相关资源
    最近更新 更多