在youtube上上传视频 [英] Upload video on youtube
问题描述
这是我的演示文稿视图
Default.aspx
this my presentation view
Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" EnableSessionState="True" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!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 id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form2" runat="server" method="post">
<asp:Label ID="l1" Text="" runat="server"></asp:Label>
<div>
<asp:Label ID="lbltitle" runat="server" Text="Title"></asp:Label><br />
<asp:TextBox ID="txttitle" runat="server"></asp:TextBox><br/>
<asp:Label ID="lbldescription" runat="server" Text="Description"></asp:Label><br/>
<asp:TextBox ID="txtDescription" Rows="5" TextMode="MultiLine" Columns="5" runat="server"
Height="46px" Width="125px"></asp:TextBox><br/>
<asp:Label ID="lblCatogery" runat="server" Text="Catogery"></asp:Label><br/>
<asp:DropDownList ID="ddlcatogery" runat="server" Height="16px" Width="123px">
<asp:ListItem Value="Autos">Autos & Vehicles</asp:ListItem>
<asp:ListItem Value="Music">Music</asp:ListItem>
<asp:ListItem Value="Animals">Pets & Animals</asp:ListItem>
<asp:ListItem Value="Sports">Sports</asp:ListItem>
<asp:ListItem Value="Travel">Travel & Events</asp:ListItem>
<asp:ListItem Value="Games">Gadgets & Games</asp:ListItem>
<asp:ListItem Value="Comedy">Comedy</asp:ListItem>
<asp:ListItem Value="People">People & Blogs</asp:ListItem>
<asp:ListItem Value="News">News & Politics</asp:ListItem>
<asp:ListItem Value="Entertainment">Entertainment</asp:ListItem>
<asp:ListItem Value="Education">Education</asp:ListItem>
<asp:ListItem Value="Howto">Howto & Style</asp:ListItem>
<asp:ListItem Value="Nonprofit">Nonprofit & Activism</asp:ListItem>
<asp:ListItem Value="Tech">Science & Technology</asp:ListItem>
</asp:DropDownList><br />
<asp:Label ID="lblkeywords" runat="server" Text="Key words"></asp:Label><br/>
<asp:TextBox ID="txtkeywords" runat="server"></asp:TextBox><br/><br />
<asp:FileUpload ID="FileUpload1" runat="server" />
<br /><br />
<asp:Button ID="Button1" runat="server" Text="Upload on youtube" onclick="Button1_Click" /> <br />
</div>
</form>
<div>
</div>
</body>
</html>
Default.aspx.cs
使用System;
使用System.Configuration;
使用Google.YouTube;
使用Google.GData.YouTube;
使用Google。 GData.Client;
使用Google.GData.Extensions.MediaRss;
使用System.Threading;
public partial class _Default:System.Web.UI.Page
{
private static readonly string YouTubeDeveloperKey = ConfigurationManager.AppSettings [YouTubeDeveloperKey];
private static readonly string YouTubeCompany = ConfigurationManager.AppSettings [YouTubeCompany];
private static readonly string YoutubeUserName = ConfigurationManager.AppSettings [YoutubeUserName];
private static readonly string YoutubePassword = ConfigurationManager.AppSettings [YoutubePassword];
string youtubeurl;
protected void Page_Load(object sender,EventArgs e)
{
}
protected void Button1_Click(object sender,EventArgs e)
{
Session [title] = txttitle.Text;
Session [description] = txtDescription.Text;
string FileName = FileUpload1 .FileName;
string fillPath = FileUpload1.PostedFile.FileName;
string content = FileUpload1.PostedFile.ContentType;
var newp = Server。 MapPath(download /+ FileName);
FileUpload1.SaveAs(Server.MapPath(download /+ FileName));
尝试
{
var settings = new YouTubeRequestSettings(Ramdeo,YouTubeDeveloperKey,YoutubeUserName,YoutubePassword)
{
Timeout = int.MaxValue
};
YouTubeRequest request = new YouTubeRequest(设置);
视频newVideo = new视频();
newVideo.Title = txttitle.Text.Trim();
newVideo.Tags.Add(new MediaCategory(ddlcatogery.SelectedItem.Text,YouTubeNameTable.CategorySchema ));
newVideo.Description = txtDescription.Text.Trim();
newVideo.Keywords = txtkeywords.Text.Trim();
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(newp,content);
视频A = request.Upload(newVideo);
System.IO.File.Delete(Request.PhysicalApplicationPath +download /+ FileName) ;
会话[youtubeurl] =http://www.youtube.com/v/+ A.VideoId +& hl = en_US& f s = 1& rel = 0;
Response.Redirect(viewVideo.aspx);
//Response.Redirect( viewVideo.aspx?Name =+ txttitle.Text +descr =+ txtDescription.Text +url =+ l1.Text);
}
catch(例外情况)
{
}
}
}
有时候这段代码有时不起作用。请帮助我,我现在很累。自从10天以来我一直在研究这个问题。
请...............帮我...
如果有可能的话再给代码上传视频在ASP.NET中使用API 3.0
Default.aspx.cs
using System;
using System.Configuration;
using Google.YouTube;
using Google.GData.YouTube;
using Google.GData.Client;
using Google.GData.Extensions.MediaRss;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
private static readonly string YouTubeDeveloperKey = ConfigurationManager.AppSettings["YouTubeDeveloperKey"];
private static readonly string YouTubeCompany = ConfigurationManager.AppSettings["YouTubeCompany"];
private static readonly string YoutubeUserName = ConfigurationManager.AppSettings["YoutubeUserName"];
private static readonly string YoutubePassword = ConfigurationManager.AppSettings["YoutubePassword"];
string youtubeurl;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
Session["title"] = txttitle.Text;
Session["description"] = txtDescription.Text;
string FileName = FileUpload1.FileName;
string fillPath = FileUpload1.PostedFile.FileName;
string content = FileUpload1.PostedFile.ContentType;
var newp = Server.MapPath("download/" + FileName);
FileUpload1.SaveAs(Server.MapPath("download/" + FileName));
try
{
var settings = new YouTubeRequestSettings("Ramdeo", YouTubeDeveloperKey, YoutubeUserName, YoutubePassword)
{
Timeout = int.MaxValue
};
YouTubeRequest request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = txttitle.Text.Trim();
newVideo.Tags.Add(new MediaCategory(ddlcatogery.SelectedItem.Text, YouTubeNameTable.CategorySchema));
newVideo.Description = txtDescription.Text.Trim();
newVideo.Keywords = txtkeywords.Text.Trim();
newVideo.YouTubeEntry.Private = false;
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(newp, content);
Video A = request.Upload(newVideo);
System.IO.File.Delete(Request.PhysicalApplicationPath + "download/" + FileName);
Session["youtubeurl"] = "http://www.youtube.com/v/" + A.VideoId + "&hl=en_US&fs=1&rel=0";
Response.Redirect("viewVideo.aspx");
//Response.Redirect("viewVideo.aspx?Name=" + txttitle.Text+"descr="+txtDescription.Text+"url="+l1.Text);
}
catch(Exception ex)
{
}
}
}
Sometime this code works sometimes not.please help me i am tired now.i have been working on this problem since 10 days.
please...............help me...
if it is possible then give the code to upload video using API 3.0 in ASP.NET
推荐答案
阅读以下答案。您需要验证登录尝试。
1. .Net YouTube API凭据无效 [ ^ ]
2. YouTube OAuth:为什么某些帐户会向我提供凭据无效? [ ^ ]
Read the following answers. You need to verify the login attempt.
1. .Net YouTube API Invalid Credentials[^]
2. YouTube OAuth: Why do some accounts give me "Invalid Credentials"?[^]
这篇关于在youtube上上传视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!