2

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

我已经按照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 重构它。

有任何想法吗?

4

2 回答 2

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

于 2010-03-03T19:23:43.050 回答
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;

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

于 2010-03-04T10:23:32.040 回答