Uploading on Youtube via HTTP Post
- by sajid.nizami
I am following the steps provided on this link
[http://code.google.com/apis/youtube/2.0/developers_guide_dotnet.html#Browser_based_Upload][1]
Whenever I try to upload anything using this method, I get a HTTP 400 error saying that the next_url is not provided. Code is pretty simple and is a copy of Google's own code.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BrowserUpload.aspx.cs" Inherits="BrowserUpload" %>
<%@ Import Namespace="Google.YouTube" %>
<%@ Import Namespace="Google.GData.Extensions.MediaRss" %>
<%@ Import Namespace="Google.GData" %>
<%@ Import Namespace="Google.GData.YouTube" %>
<%@ Import Namespace="Google.GData.Client" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function checkForFile() {
if (document.getElementById('file').value) {
return true;
}
document.getElementById('errMsg').style.display = '';
return false;
}
</script>
</head>
<body>
<%
YouTubeRequestSettings settings =
new YouTubeRequestSettings("Danat",
"API-KEY",
"loginid",
"password"
);
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = "My Test Movie";
newVideo.Tags.Add(new MediaCategory("Autos", YouTubeNameTable.CategorySchema));
newVideo.Keywords = "cars, funny";
newVideo.Description = "My description";
newVideo.YouTubeEntry.Private = false;
newVideo.Tags.Add(new MediaCategory("mydevtag, anotherdevtag",
YouTubeNameTable.DeveloperTagSchema));
FormUploadToken token = request.CreateFormUploadToken(newVideo);
%>
<form action="<%= token.Url %>?next_url=<%= Server.UrlEncode("http://www.danatev.com") %>"
name="PostToYoutube" method="post" enctype="multipart/form-data" onsubmit="return checkForFile();" >
<input id="file" type="file" name="file" />
<div id="errMsg" style="display: none; color: red">
You need to specify a file.
</div>
<input type="hidden" name="token" value="<%= token.Token %>" />
<input type="submit" value="go" />
</form>