我尝试使用youtube java api通过我的java桌面应用程序连接我的youtube帐户,我已按照本指南:https://developers.google.com/youtube/2.0/developers_guide_java?hl=pt-BR#ClientLogin_for_Installed_Applications看起来很简单,但我收到错误,这是我的代码:< / p>
String developer_key = "key123456789"; // Registered developer key
String application_name = "app"; // Registered application name
String user_account = "user@gmail.com"; // 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 :(得分:0)
我发现了问题,我在代理下,(我已经更改了系统属性以连接此代理),但youtube使用https进行http的用户登录intead,因此在代理设置中我刚刚添加一个https代理,现在有效,这是我的代码:
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());
}
}
);
}
}