0

I am trying to upload to youtube Via its API, And while I am doing it localy it works fine. How ever when it's on my Azure App it gets an (403) Forbidden

Here is my code:

YouTubeRequestSettings settings = new YouTubeRequestSettings("XXXXX", token, userName, Password);
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();

newVideo.Title = "Test";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "car";

newVideo.Description = "My first try";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("devTag",
  YouTubeNameTable.DeveloperTagSchema));
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(**SaveFileToLocal**(fileUpload), fileUpload.ContentType);
Video createdVideo = request.Upload(newVideo);

private string **SaveFileToLocal**(HttpPostedFileBase fileUpload)
{
    string uploadedFilePath;
    if (Local)
    {
        var uploadPath = Server.MapPath("~/AlbumsUploads//" + "RD");
        uploadedFilePath = Path.Combine(uploadPath, fileUpload.FileName);
    }
    else
    {
        LocalResource localResource = RoleEnvironment.GetLocalResource("LocalWebRoleStorage");
        string[] paths = { localResource.RootPath, DateTime.Now.Ticks.ToString() + "_temp" + fileUpload.FileName.Substring(fileUpload.FileName.LastIndexOf('.')) };
        uploadedFilePath = Path.Combine(paths);
    }
    using (var fs = new FileStream(uploadedFilePath, FileMode.Create))
    {
        var buffer = new byte[fileUpload.InputStream.Length];
        fileUpload.InputStream.Read(buffer, 0, buffer.Length);
        fs.Write(buffer, 0, buffer.Length);
    }
    return uploadedFilePath;
}   

And here is my exception.

Google.GData.Client.GDataRequestException: Execution of request failed: https://uploads.gdata.youtube.com/feeds/api/users/default/uploads ---> System.Net.WebException: The remote server returned an error: (403) Forbidden.
at System.Net.HttpWebRequest.GetResponse()
at Google.GData.Client.GDataRequest.Execute()
--- End of inner exception stack trace ---
at Google.GData.Client.GDataRequest.Execute()
at Google.GData.Client.GDataGAuthRequest.Execute(Int32 retryCounter)
at Google.GData.Client.MediaService.EntrySend(Uri feedUri, AtomBase baseEntry, GDataRequestType type, AsyncSendData data)
at Google.GData.Client.Service.Insert(Uri feedUri, AtomEntry newEntry, AsyncSendData data)
at Google.YouTube.YouTubeRequest.Upload(String userName, Video v)
at MvcWedApp.Controllers.AlbumManagementController.UploadToYouTube(HttpPostedFileBase fileUpload, Int32 albumId)
at MvcWedApp.Controllers.AlbumManagementController.Upload(Nullable`1 chunk, String name) 

Any help anyone?

6
  • It seems like the constructor for YouTubeRequestSettings that takes a username and password is this one (5 arguments) rather than your 4 argument constructor? May 22, 2012 at 11:41
  • Thanks for the reply. but YouTubeRequestSettings has 4 overload. plus it does work on my local env, so there is nothing wrong with that.
    – user730895
    May 22, 2012 at 11:59
  • Is there a possibility that I don't have the right permissions on my Azure RoleEnvironment LocalResource files?
    – user730895
    May 22, 2012 at 12:02
  • I would like to see your Azure Solution. Is there a way you can send me the link to get your full Azure project? This will help me to dig faster. May 22, 2012 at 16:43
  • AvkashChauhan, Sorry, That won't be possible. Mainly cause the project is owned by a commercial company which won't allow it. But if you have any specific code that you want to see. I can do that.
    – user730895
    May 23, 2012 at 12:10

2 Answers 2

1

The problem is that YourTube server is rejecting your authorization request with 403 it means from ASP.NET Web Role the authentication request is failed by some reason. It also explains that you haven't even started uploading yet so it could be networking related access issues potentially.

And in order to troubleshoot such issues, you can try the following:

  1. RDP to your Azure VM and install Fiddler and collect the network traffic. Compare this your desktop traffic and see what could be the issue.
  2. You can also install Network Monitor in your Azure VM compare the network traffic to understand if it is an issues due to authentication was failed or there is some issues with Network IP/Port etc.

Also when you test locally, does it work if your ASP.NET application runs in Computer Emulator?

Based on below document, you are stuck with Google Authorization sequence so that would be the first place to troubleshoot. Based on my experience Fiddler is your best friend the understand the root cause and then you can find the solution: https://developers.google.com/youtube/2.0/developers_guide_protocol#Process_Flows_for_Uploading_Videos

Note: By any means this is not a solution however I am writing here to explain how to troubleshoot this issue.

0
1

I ran into a similar problem to your problem:

I talked about this situation with Azure Technical Evangelist and he thinks this problem occur when the Youtube API’s port close (80 and 443), Maybe It’s about Server Firewall properties. So I tried to change many way (Remote to Server and change firewall properties etc ) about open this ports but It doesn’t work.

Finally I solved my problem and I can understand It is not about port access.** I authorized acces to our google account and granted our cloud services with this url**: We understand, we have to generate a new specific password for each application. And also you must generate a DevKey with this URL :

Maybe it could be related to problems ...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.