我正在尝试通过其 API 上传到 youtube,而当我在本地进行时,它工作正常。当它在我的 Azure 应用程序上时,它如何获得 (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)
有什么帮助吗?