【问题标题】:How to upload to YouTube using the API via a Proxy Server如何通过代理服务器使用 API 上传到 YouTube
【发布时间】:2011-01-23 08:52:42
【问题描述】:

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

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

有什么想法吗?

【问题讨论】:

    标签: c# .net youtube-api


    【解决方案1】:

    听起来您的代理需要凭据。必须在代码中提供凭据;我目前正在搜索 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

    【讨论】:

    • 您好,感谢您的快速回复。我会在早上尝试这个建议
    【解决方案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;
    

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

    【讨论】:

      猜你喜欢
      • 2011-02-22
      • 2014-08-30
      • 2016-06-25
      • 2011-03-02
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多