Wednesday, August 20, 2014

How to get all information of YouTube video

How to get all information of YouTube video

 To get all video information, use this syntax:

http://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk
Bolded part is video ID. This link will return all video data in different formats. Default format of feed is atom, other valid values are rss, json and json-in-script. Use alt parameter to change format, for example, to return video data in form of RSS feed set alt=rss, like this:
http://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?alt=rss
Returned feed contains data like video title, description, categories, author, date published, rating, duration, keywords, statistics etc. You can load this feed into XPathDocument object and access items using XPath queries. Example code that finds video title and description could look like this:
[ C# ]
using System;
 
// We need System.Xml.XPath namespace to query XML
using System.Xml.XPath;
 
public partial class _Default : System.Web.UI.Page
{
 
 protected void Page_Load(object sender, EventArgs e)
 {
   // Load video information from YouTube
   XPathDocument videoInfo = new XPathDocument(
     "http://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?alt=rss");
 
   // Create XPath navigator
   XPathNavigator videoInfoNavigator = videoInfo.CreateNavigator();
 
   // Gets YouTube video title
   string Title = videoInfoNavigator.SelectSingleNode("/item[1]/title").Value;
   // Gets YouTube video description
   string Description = videoInfoNavigator.SelectSingleNode("/item[1]/description").Value;
 
   // Write results
   Response.Write("Video title: " + Title + "
"
+

     "Description: " + Description);
  }
}
[ VB.NET ]
Imports System
Imports System.Web
 
' We need System.Xml.XPath namespace to query XML
Imports System.Xml.XPath
 
Partial Class DefaultVBNET
 Inherits System.Web.UI.Page
 
 Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
   ' Load video information from YouTube
   Dim videoInfo As XPathDocument = New XPathDocument( _
     "http://gdata.youtube.com/feeds/api/videos/5P6UU6m3cqk?alt=rss")
 
   ' Create XPath navigator
   Dim videoInfoNavigator As XPathNavigator = videoInfo.CreateNavigator()
 
   ' Gets YouTube video title
   Dim Title As String = videoInfoNavigator.SelectSingleNode("/item[1]/title").Value
   ' Gets YouTube video description
   Dim Description As String = videoInfoNavigator.SelectSingleNode("/item[1]/description").Value
 
   ' Output results
   Response.Write("Video title: " & Title & "
"
& _

     "Description: " & Description)
 End Sub
End Class

 


If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website

0 comments:

Post a Comment