如何使用API​​通过代理服务器上传到YouTube

时间:2010-03-03 19:09:42

标签: c# .net youtube-api

我正在构建一个应用程序,允许用户将视频上传到您管道上的特定帐户。

我已按照http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html上的示例进行直接上传,但在调用request.Upload(newVideo)时,我现在需要进行407代理身份验证。

我找到了一个使用代理(http://code.google.com/p/google-gdata/wiki/WebProxySetup)的Google日历服务示例,但似乎无法解决如何为YouTube重构它。

有什么想法吗?

2 个答案:

答案 0 :(得分:5)

听起来您的代理需要凭据。证书必须以代码提供;我正在搜索Google API的源代码来查找它,因为它们有自己的自定义请求对象。

与此同时,您可以使用默认代理而不是来使其工作。修改app.config或web.config以将其插入正确的位置:

<configuration>
 <system.net>
  <defaultProxy>
   <proxy usesystemdefault="false"/>
  </defaultProxy>
 </system.net>
</configuration>

修改

好的,在做了一些挖掘之后,这就是我想法你将如何重构你为特定请求链接的指令。假设您已按如下方式创建了YouTubeRequest:

YouTubeRequest request = new YouTubeRequest(settings);

以下是链接中的重构说明:

YouTubeRequest request = new YouTubeRequest(settings);
GDataRequestFactory f = (GDataRequestFactory) request.Service.RequestFactory;
IWebProxy iProxy = WebRequest.DefaultWebProxy;
WebProxy myProxy = new WebProxy(iProxy.GetProxy(query.Uri));
// potentially, setup credentials on the proxy here
myProxy.Credentials = CredentialsCache.DefaultCredentials;
myProxy.UseDefaultCredentials = true;
f.Proxy = myProxy;

以下是我的消息来源:

http://google-gdata.googlecode.com/svn/docs/folder56/T_Google_YouTube_YouTubeRequest.htm

http://google-gdata.googlecode.com/svn/docs/folder53/P_Google_GData_Client_FeedRequest_1_Service.htm

http://google-gdata.googlecode.com/svn/docs/folder19/P_Google_GData_Client_Service_RequestFactory.htm

答案 1 :(得分:2)

使用Randolpho提供的代码,我设法获得了成功呼叫YouTube的代码。我设法将代码简化为

YouTubeRequest request = new YouTubeRequest(settings);
GDataRequestFactory f = (GDataRequestFactory)request.Service.RequestFactory;
WebProxy myProxy = new WebProxy("http://proxy-server:port/", true);
myProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
f.Proxy = myProxy;

代码将使用可访问互联网的服务帐户运行,因此我不需要在代码中提供用户名和密码。