我正在尝试通过其API上传到youtube 虽然我在做它本地它工作正常。 然而,当它在我的Azure应用程序上时,它获得了(403)禁止
这是我的代码:
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)
有人帮忙吗?
答案 0 :(得分:1)
问题是,YourTube服务器拒绝您的授权请求403,这意味着从ASP.NET Web角色验证请求由于某种原因而失败。它还解释了您尚未开始上传,因此它可能是与网络相关的访问问题。
为了解决此类问题,您可以尝试以下方法:
此外,当您在本地测试时,如果您的ASP.NET应用程序在计算机模拟器中运行,它是否有效?
根据以下文档,您将无法使用Google授权序列,因此这将是第一个排除故障的地方。根据我的经验 Fiddler是您最了解根本原因的朋友,然后您可以找到解决方案: https://developers.google.com/youtube/2.0/developers_guide_protocol#Process_Flows_for_Uploading_Videos
注意:无论如何,这不是解决方案,但我在此写这篇文章来解释如何解决这个问题。
答案 1 :(得分:1)
我遇到了类似的问题:
我与Azure技术宣传员讨论了这种情况,他认为当Youtube API的端口关闭(80和443)时,会出现此问题,可能是关于服务器防火墙属性。 所以我试图改变许多方式(远程到服务器和更改防火墙属性等)关于打开这个端口,但它不起作用。
最后我解决了我的问题,我可以理解它不是关于端口访问。** I authorized acces to our google account and granted our cloud services with this url**: 我们知道,我们必须为每个应用程序生成一个新的特定密码。 And also you must generate a DevKey with this URL :
也许它可能与问题有关......