Thulasiram pakala

Thulasiram pakala

  • 900
  • 872
  • 114.1k

how to upload videos to utube

Jul 13 2016 1:49 AM
hi i want to upload video  to you tube using asp.net separate channel  i am using this code but not stored so kindly any body rlp for this send dll files also
 
 
protected void Btnsubmit_Click(object sender, EventArgs e)
{
try
{
string videopath, videotitle, videodesc;
string username = "[email protected]";
string password = "09543262856";

// Response.Redirect("https://www.youtube.com/[email protected]&&09543262856");

// Response.Redirect("https://www.youtube.com/upload");
string c = System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = "D:\\videosmpeg\\" + upload.PostedFile.FileName;// System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = upload.PostedFile.FileName;
videotitle = upload.FileName;
//Stream fs2 = default(Stream);
//fs2 = upload.PostedFile.InputStream;
//BinaryReader br2 = new BinaryReader(fs2);
//byte[] content;
//video_upload = br2.ReadBytes(upload.PostedFile.ContentLength);

videodesc = "MANGO ";
UploadVideo(videopath, videotitle, videodesc);
}
catch (Exception exception)
{
Response.Write("Upload failed: " + exception.Message);
}
//String CLIENT_ID = "ATIC";
//String CLIENT_SECRET = "some_secret";

//// Register the authenticator and create the service
//var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
//var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
//var service = new DriveService(new BaseClientService.Initializer()
//{
// Authenticator = auth
//});

//File body = new File();
//body.Title = "My document";
//body.Description = "A test document";
//body.MimeType = "text/plain";

//byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
//System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

//FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
//request.Upload();

//File file = request.ResponseBody;

}

public static void UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;

// string url = "https://www.youtube.com/upload";
//string devkey = "https://www.youtube.com/upload";



//"AIzaSyCQIEWyw4nOpFiZCXKnw4Cad7Vd-PV5A1o"; //"aticuasb-1359";
string username = "[email protected]";
string password = "09543262856";
settings = new YouTubeRequestSettings("[email protected]", devkey, username, password) { Timeout = 10000000 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
// newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.Keywords = "AGRI";
newVideo.Tags.Add(new MediaCategory("ATIC", YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// Stream stream = new MemoryStream(content);

// Stream stream = new MemoryStream(content);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource(stream, fileName, contentType);
//Video createdVideo = request.Upload(newVideo);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\Demo\\YoutubeVideoUpload\\e3a6f15f-4a8c-40d5-9cc8-c45d30b7f9ed.mov", "video/quicktime");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
// return createdVideo.VideoId;
}

protected void Btnsubmit_Click(object sender, EventArgs e)
{

// byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
//byte[] file = File.ReadAllBytes(videoFilePath);

//using (var fileStream = new FileStream(videoFilePath, FileMode.Open))
//{
//Uri uri = new Uri("https://www.googleapis.com/upload/youtube/v3/videos?part=snippet");
//WebClient wc = new WebClient();

//wc.Headers.Add("Authorization", "Bearer {access_token}");
//byte[] file = File.ReadAllBytes(Server.MapPath("/videos/test.mp4"));
//byte[] response = wc.UploadData(uri, file);

//string jSonResult = String.Format("\nResult received was {0}",
// Encoding.ASCII.GetString(response));
//return jSonResult;

//Uri uri = new Uri("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet,status");

//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//request.Method = "POST";
//request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authToken);
//request.ContentLength = jsonBytes.Length;
//request.ContentType = "application/json; charset=utf-8";
//request.Headers.Add("X-Upload-Content-Length", fileStream.Length.ToString());
//request.Headers.Add("X-Upload-Content-Type", "video/*");

//string location = string.Empty;
//using (Stream dataStream = request.GetRequestStream())
//{
// dataStream.Write(jsonBytes, 0, jsonBytes.Length);
//}
//try
//{
// using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
// {
// location = response.Headers["Location"];
// }
//}
//catch (WebException ex)
//{
// Response.Write(ex.ToString());
//}

//request = (HttpWebRequest)WebRequest.Create(location);
//request.Method = "PUT";
//request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authToken);
//request.ContentLength = fileStream.Length;
//request.ContentType = "video/*";
//using (Stream dataStream = request.GetRequestStream())
//{
// byte[] buffer = new byte[fileStream.Length];
// var data = fileStream.Read(buffer, 0, buffer.Length);
// dataStream.Write(buffer, 0, data);
// //dataStream.Write(file, 0, file.Length);
//}
//try
//{
// using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
// {
// }
//}
//catch (WebException ex)
//{
// Response.Write(ex.ToString());
//}




try
{
string videopath, videotitle, videodesc;
string username = "[email protected]";
string password = "09543262856";

// Response.Redirect("https://www.youtube.com/[email protected]&&09543262856");

// Response.Redirect("https://www.youtube.com/upload");
string c = System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = "D:\\videosmpeg\\" + upload.PostedFile.FileName;// System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = upload.PostedFile.FileName;
videotitle = upload.FileName;
//Stream fs2 = default(Stream);
//fs2 = upload.PostedFile.InputStream;
//BinaryReader br2 = new BinaryReader(fs2);
//byte[] content;
//video_upload = br2.ReadBytes(upload.PostedFile.ContentLength);

videodesc = "MANGO ";
UploadVideo(videopath, videotitle, videodesc);
}
catch (Exception exception)
{
Response.Write("Upload failed: " + exception.Message);
}
//String CLIENT_ID = "ATIC";
//String CLIENT_SECRET = "some_secret";

//// Register the authenticator and create the service
//var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
//var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
//var service = new DriveService(new BaseClientService.Initializer()
//{
// Authenticator = auth
//});

//File body = new File();
//body.Title = "My document";
//body.Description = "A test document";
//body.MimeType = "text/plain";

//byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
//System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

//FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
//request.Upload();

//File file = request.ResponseBody;

}

public static void UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;

// string url = "https://www.youtube.com/upload";
//string devkey = "https://www.youtube.com/upload";



//"AIzaSyCQIEWyw4nOpFiZCXKnw4Cad7Vd-PV5A1o"; //"aticuasb-1359";
string username = "[email protected]";
string password = "09543262856";
settings = new YouTubeRequestSettings("[email protected]", devkey, username, password) { Timeout = 10000000 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
// newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.Keywords = "AGRI";
newVideo.Tags.Add(new MediaCategory("ATIC", YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// Stream stream = new MemoryStream(content);

// Stream stream = new MemoryStream(content);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource(stream, fileName, contentType);
//Video createdVideo = request.Upload(newVideo);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\Demo\\YoutubeVideoUpload\\e3a6f15f-4a8c-40d5-9cc8-c45d30b7f9ed.mov", "video/quicktime");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
// return createdVideo.VideoId;
}

protected void Btnsubmit_Click(object sender, EventArgs e)
{

// byte[] jsonBytes = Encoding.UTF8.GetBytes(json);
//byte[] file = File.ReadAllBytes(videoFilePath);

//using (var fileStream = new FileStream(videoFilePath, FileMode.Open))
//{
//Uri uri = new Uri("https://www.googleapis.com/upload/youtube/v3/videos?part=snippet");
//WebClient wc = new WebClient();

//wc.Headers.Add("Authorization", "Bearer {access_token}");
//byte[] file = File.ReadAllBytes(Server.MapPath("/videos/test.mp4"));
//byte[] response = wc.UploadData(uri, file);

//string jSonResult = String.Format("\nResult received was {0}",
// Encoding.ASCII.GetString(response));
//return jSonResult;

//Uri uri = new Uri("https://www.googleapis.com/upload/youtube/v3/videos?uploadType=resumable&part=snippet,status");

//HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
//request.Method = "POST";
//request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authToken);
//request.ContentLength = jsonBytes.Length;
//request.ContentType = "application/json; charset=utf-8";
//request.Headers.Add("X-Upload-Content-Length", fileStream.Length.ToString());
//request.Headers.Add("X-Upload-Content-Type", "video/*");

//string location = string.Empty;
//using (Stream dataStream = request.GetRequestStream())
//{
// dataStream.Write(jsonBytes, 0, jsonBytes.Length);
//}
//try
//{
// using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
// {
// location = response.Headers["Location"];
// }
//}
//catch (WebException ex)
//{
// Response.Write(ex.ToString());
//}

//request = (HttpWebRequest)WebRequest.Create(location);
//request.Method = "PUT";
//request.Headers.Add(HttpRequestHeader.Authorization, "Bearer " + authToken);
//request.ContentLength = fileStream.Length;
//request.ContentType = "video/*";
//using (Stream dataStream = request.GetRequestStream())
//{
// byte[] buffer = new byte[fileStream.Length];
// var data = fileStream.Read(buffer, 0, buffer.Length);
// dataStream.Write(buffer, 0, data);
// //dataStream.Write(file, 0, file.Length);
//}
//try
//{
// using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
// {
// }
//}
//catch (WebException ex)
//{
// Response.Write(ex.ToString());
//}




try
{
string videopath, videotitle, videodesc;
string username = "[email protected]";
string password = "09543262856";

// Response.Redirect("https://www.youtube.com/[email protected]&&09543262856");

// Response.Redirect("https://www.youtube.com/upload");
string c = System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = "D:\\videosmpeg\\" + upload.PostedFile.FileName;// System.IO.Path.GetFullPath(upload.PostedFile.FileName);
videopath = upload.PostedFile.FileName;
videotitle = upload.FileName;
//Stream fs2 = default(Stream);
//fs2 = upload.PostedFile.InputStream;
//BinaryReader br2 = new BinaryReader(fs2);
//byte[] content;
//video_upload = br2.ReadBytes(upload.PostedFile.ContentLength);

videodesc = "MANGO ";
UploadVideo(videopath, videotitle, videodesc);
}
catch (Exception exception)
{
Response.Write("Upload failed: " + exception.Message);
}
//String CLIENT_ID = "ATIC";
//String CLIENT_SECRET = "some_secret";

//// Register the authenticator and create the service
//var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
//var auth = new OAuth2Authenticator<NativeApplicationClient>(provider, GetAuthorization);
//var service = new DriveService(new BaseClientService.Initializer()
//{
// Authenticator = auth
//});

//File body = new File();
//body.Title = "My document";
//body.Description = "A test document";
//body.MimeType = "text/plain";

//byte[] byteArray = System.IO.File.ReadAllBytes("document.txt");
//System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

//FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
//request.Upload();

//File file = request.ResponseBody;

}

public static void UploadVideo(string FilePath, string Title, string Description)
{
YouTubeRequestSettings settings;
YouTubeRequest request;

// string url = "https://www.youtube.com/upload";
//string devkey = "https://www.youtube.com/upload";



//"AIzaSyCQIEWyw4nOpFiZCXKnw4Cad7Vd-PV5A1o"; //"aticuasb-1359";
string username = "[email protected]";
string password = "09543262856";
settings = new YouTubeRequestSettings("[email protected]", devkey, username, password) { Timeout = 10000000 };
request = new YouTubeRequest(settings);
Video newVideo = new Video();
newVideo.Title = Title;
newVideo.Description = Description;
// newVideo.Private = true;
newVideo.YouTubeEntry.Private = false;
newVideo.Keywords = "AGRI";
newVideo.Tags.Add(new MediaCategory("ATIC", YouTubeNameTable.CategorySchema));
newVideo.YouTubeEntry.Location = new GeoRssWhere(37, -122);
// Stream stream = new MemoryStream(content);

// Stream stream = new MemoryStream(content);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource(stream, fileName, contentType);
//Video createdVideo = request.Upload(newVideo);
// newVideo.YouTubeEntry.MediaSource = new MediaFileSource("C:\\Demo\\YoutubeVideoUpload\\e3a6f15f-4a8c-40d5-9cc8-c45d30b7f9ed.mov", "video/quicktime");
newVideo.YouTubeEntry.MediaSource = new MediaFileSource(FilePath, "video/flv");
Video createdVideo = request.Upload(newVideo);
// return createdVideo.VideoId;
}

 

Answers (1)