English 中文(简体)
上传至Youtube, 通过 Azure 的 API 上传到 Youtube
原标题:Upload to Youtube via its API from Azure

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

这是我的代码:

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;
}   

这是我的例外。

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) 

有人能帮上忙吗?

问题回答

问题在于 YourTube 服务器拒绝您的授权请求, 403 代表来自 ASP.NET Web 角色 的认证请求因某种原因失败 。 它还解释了您甚至还没有开始上传, 从而有可能成为联网相关访问问题 。

为了解决这类问题,您可以尝试以下方法:

  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.

如果您的 ASP. NET 应用程序在计算机模拟器中运行, 本地测试是否有效?

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

说明:无论如何,这不是一个解决办法,我在此写信解释如何解决这一问题。

我遇到了一个类似的问题 与你的问题:

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 :

也许它可能与问题有关...





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签