2010-03-03 109 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

相關問題