OWASP O2 Platform Blog

Accessing YouTube via its C# API

Here are two examples on how to use Google’s C# API to access YouTube (using O2 Platform‘s Quick Develoment Gui).

Example 1: List the latest feeds

panel.clear();
var googleDevKey = "AI39si4VZRef7hm9N-RBZ5u-5x5N2lIgyEvv45dGgDxCJjltduhlnF9tTmfWV55tFMUWbnThHybbipiXiEufJueJPpF65lkyjg ";
var settings = new YouTubeRequestSettings("API_YouTube",googleDevKey);

var youTubeRequest = new YouTubeRequest(settings);
Feed<Video> feed = youTubeRequest.GetStandardFeed(YouTubeQuery.MostPopular);
panel.add_TableList().show(feed.Entries);

return "done";

//using Google.YouTube
//using Google.GData.Client
//using Google.GData.YouTube
//O2Ref:Google.GData.Client.dll
//O2Ref:Google.GData.YouTube.dll
//O2Ref:Google.GData.Extensions.dll

 

Example 2: Upload Video

var account = @"C:\O2\_USERDATA\Accounts.xml".credential("YouTube");panel.clear();

var googleDevKey = "AI39si4VZRef7hm9N-RBZ5u-5x5N2lIgyEvv45dGgDxCJjltduhlnF9tTmfWV55tFMUWbnThHybbipiXiEufJueJPpF65lkyjg ";

var settings = new YouTubeRequestSettings("API_YouTube",googleDevKey, account.UserName, account.Password);

var videoToUpload= @"C:\O2\DemoData\O2Videos\_Test_Video_1.avi";

var youTubeRequest = new YouTubeRequest(settings);
var video = new Video();
video.Title = "First Test 1";
video.Title = "This is the first YouTube API test";
video.Keywords = "O2 Test";
MediaCategory category = new MediaCategory("Technology");
category.Attributes["scheme"] = YouTubeService.DefaultCategory;
video.Tags.Add(category);
video.MediaSource = new MediaFileSource(videoToUpload, "video/avi");

return youTubeRequest.Upload(video);
return "done";

//O2File:SecretData_ExtensionMethods.cs

//using Google.YouTube
//using Google.GData.Client
//using Google.GData.YouTube
//using Google.GData.Extensions.MediaRss
//O2Ref:Google.GData.Client.dll
//O2Ref:Google.GData.YouTube.dll
//O2Ref:Google.GData.Extensions.dll

October 19, 2010 - Posted by | Interoperability

2 Comments »

  1. Note, the MediaCategory has to be set to

    MediaCategory category = new MediaCategory(“Tech”);

    the example above was working before, but YouTube must have made some changes

    Comment by o2platform | October 19, 2010 | Reply

  2. […] on the Accessing YouTube via its C# API script , here are two more uses of the YouTube C# […]

    Pingback by O2 Script to get YouTube videos list « OWASP O2 Platform Blog | April 21, 2012 | Reply


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: