views:

493

answers:

2

I am building an application which will allow users to upload videos to a specific account on you tube.

I have followed the examples on http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html for direct upload however I am now getting a 407 proxy authentication required when request.Upload(newVideo) is called.

I've found an example for the Google Calendar Service using a proxy ( http://code.google.com/p/google-gdata/wiki/WebProxySetup )but can't seem to work out how to refactor it for YouTube.

Any ideas?

A: 

It sounds like your proxy requires credentials. Credentials have to be supplied in code; I'm currently trawling the source for the Google API to find it, since they have their own custom request objects.

In the mean time, you might get it to work by simply not using the default proxy. Modify your app.config or web.config to insert this at the correct location:

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

Edit:

Ok, after doing some digging, here's how I think you'd refactor the instructions you linked for your specific request. Assuming you've already created a YouTubeRequest as follows:

YouTubeRequest request = new YouTubeRequest(settings);

Here are the refactored instructions from your link:

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;

Here are my sources:

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

Randolpho
Hi thanks for the quick response. I will try out the suggestion in the morning
bannypotter
+1  A: 

Using the code provided by Randolpho I managed to get the code to successfully call YouTube. I managed to simplfy the code more to

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;

The code will be running with a service account with access to the internet so I shouldn't need to provide a username and password in the code.

bannypotter
+1: Awesome. Helped me out. Thanks, man.
Jim G.