2013-10-01 54 views
0

我試着通過使用YouTube的Java API我的Java桌面應用程序在我的YouTube帳戶連接,我已經按照本指南:https://developers.google.com/youtube/2.0/developers_guide_java?hl=pt-BR#ClientLogin_for_Installed_Applications看起來很容易,但IM得到一個錯誤,here'我的代碼:錯誤與YouTube的Java API,同時設置用戶憑據

String developer_key = "key123456789"; // Registered developer key 
    String application_name = "app"; // Registered application name 
    String user_account = "[email protected]"; // Server's Youtube account 
    String user_password = "mypass"; // Server's Youtube password 

    YouTubeService service = new YouTubeService(application_name, developer_key); 

    try { 
     service.setUserCredentials(user_account, user_password); 
    } catch (AuthenticationException e) { 
     System.out.println("Error: " + e); 
    } 

,但我不斷收到此錯誤:

com.google.gdata.util.AuthenticationException: Error connecting with login URI 

誤差以setUserCredentials功能發生了,有人知道我缺少的是什麼?

回答

0

我發現了問題,我在代理下,(我已經改變了系統屬性來連接這個代理),但是youtube使用https作爲http的用戶登錄intead,所以在代理設置中我只是增加了一個HTTPS代理和現在的作品,here's我的代碼:

 if(Assets.HTTP_USE_PROXY) { 
     System.setProperty("proxySet", "true"); 
     System.setProperty("https.proxyHost", Assets.HTTP_PROXY_HOST); 
     System.setProperty("https.proxyPort", Integer.toString(Assets.HTTP_PROXY_PORT)); 
     if(Assets.HTTP_REQUIRE_AUTH) { 
      System.setProperty("https.proxyUser", Assets.HTTP_PROXY_USER); 
      System.setProperty("https.proxyPassword", Assets.HTTP_PROXY_PASSWORD); 
      Authenticator.setDefault(
         new Authenticator() { 
         public PasswordAuthentication getPasswordAuthentication() { 
          return new PasswordAuthentication(Assets.HTTP_PROXY_USER, 
            Assets.HTTP_PROXY_PASSWORD.toCharArray()); 
         } 
         } 
        ); 
     } 
    }