2010-03-03 64 views
2

我正在构建一个应用程序,该应用程序将允许用户将视频上传到您的管道上的特定帐户。如何通过代理服务器使用API​​上传到YouTube

我遵循了直接上传但是我现在得到时request.Upload(newVideo)被称为需要407代理身份验证上http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html的例子。

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

任何想法?

回答

2

使用Randolpho提供的代码,我设法让代码成功地调用YouTube。我设法simplfy代码更

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; 

的代码将与访问互联网服务帐户下运行,所以我不应该需要提供代码中的一个用户名和密码。

+0

+1的建议:太棒了。帮我出去了。谢啦。 – 2010-07-13 15:15:21

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

+0

嗨,感谢您的快速回复。我会在早上试试 – bannypotter 2010-03-03 22:43:36

相关问题