使用 Java Youtube API 通过代理上传到 Youtube [英] Uploading to Youtube via a proxy using the Java Youtube API

查看:92
本文介绍了使用 Java Youtube API 通过代理上传到 Youtube的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我想编写一个使用 Java API 将视频上传到 youtube 频道的 servlet,但我似乎找不到指定我要通过代理服务器的方法.我在这个站点上看到了一个例子,有人设法使用 C# 来做到这一点,但他们使用的类似乎不存在于 Java API 中.有没有人成功做到这一点?

So I want to write a servlet which uploads a video to a youtube channel using the Java API, but I can't seem to find a way of specifying that I want to go through a proxy server. I've seen an example on this site where someone managed to do this using C#, but the Classes they used don't seem to exist in the Java API. Has anybody managed to successfully do this?

YouTubeService service = new YouTubeService(clientID, developerKey);

YouTubeService service = new YouTubeService(clientID, developerKey);

推荐答案

我是新来的,所以我无法对帖子发表评论(并且在这个话题上有点晚),但是 Jesper,我相信这是 C#原始海报谈论的示例:如何通过代理服务器使用 API 上传到 YouTube

I'm new here so I'm unable to comment on posts (and a little late on this topic), but Jesper, I believe this is the C# sample that the original poster was talking about: How to upload to YouTube using the API via a Proxy Server

不过,我看不到将该示例移植到 Java 的直接"方式,因为 GDataRequestFactory 似乎没有任何与代理相关的字段.

I can see no "direct" way of porting that example to Java though, since the GDataRequestFactory doesn't seem to have any proxy-related fields.

我的应用程序中带有代理的 Java 客户端库也有问题.基本上,该库获取全局 Java 代理设置:

I was also having issues with the Java client Library with proxy in our application. Basically, the library picks up the global Java proxy settings:

System.getProperty("http.proxyHost");
System.getProperty("http.proxyPort"); 

但由于某种原因,并非无处不在.更准确地说,即使在 Java 中正确配置了代理服务器,YouTube 身份验证(调用 service.setUserCredentials("login", "pwd"))也会使用直接连接并忽略代理.但是视频上传(调用 service.insert(...))会正确使用代理.

but for some reason not everywhere. To be more precise, even with a proxy server properly configured in Java, YouTube authentication (calling service.setUserCredentials("login", "pwd")) would use a direct connection and ignore the proxy. But a video upload (calling service.insert(...)) would use the proxy correctly.

在官方 YouTube API 邮件列表中的人的帮助下,我能够确定这一点.问题是身份验证是使用 SSL (HTTPS) 执行的,并且由于 HTTPS 代理有一组不同的属性,因此这不起作用.解决方法是简单地设置 https.proxy* 属性(除了 http.proxy*),这样它们也指向一个有效的代理服务器:>

With the help of folks at the official YouTube API mailing list, I was able to nail this down. The issue is that the authentication is performed using SSL (HTTPS) and since there is a different set of properties for the HTTPS proxy, this didn't work. The fix is to simply set https.proxy* properties as well (in addition to http.proxy*), so that these point to a valid proxy server too:

System.getProperty("https.proxyHost");
System.getProperty("https.proxyPort"); 

这篇关于使用 Java Youtube API 通过代理上传到 Youtube的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆