public clsVideoFeedReader(string dev_key, string app_name, string username, string password) { _username = username; _password = password; _dev_key = dev_key; _app_name = app_name; Service = new YouTubeService(app_name, string.Empty, dev_key); this.setCredentials(); }
protected void SubmitVideo_ServerClick(object sender, EventArgs e) { if (String.IsNullOrEmpty(this.Title.Text) == false && String.IsNullOrEmpty(this.Description.Text) == false && String.IsNullOrEmpty(this.Category.SelectedValue) == false && String.IsNullOrEmpty(this.Keyword.Text) == false) { GAuthSubRequestFactory authFactory = new GAuthSubRequestFactory(ServiceNames.YouTube, "TesterApp"); YouTubeService service = new YouTubeService(authFactory.ApplicationName, "ytapi-FrankMantek-TestaccountforGD-sjgv537n-0", "AI39si4v3E6oIYiI60ndCNDqnPP5lCqO28DSvvDPnQt-Mqia5uPz2e4E-gMSBVwHXwyn_LF1tWox4LyM-0YQd2o4i_3GcXxa2Q" ); authFactory.Token = HttpContext.Current.Session["token"] as string; service.RequestFactory = authFactory; try { YouTubeEntry entry = new YouTubeEntry(); entry.Media = new Google.GData.YouTube.MediaGroup(); entry.Media.Description = new MediaDescription(this.Description.Text); entry.Media.Title = new MediaTitle(this.Title.Text); entry.Media.Keywords = new MediaKeywords(this.Keyword.Text); // entry.Media.Categories MediaCategory category = new MediaCategory(this.Category.SelectedValue); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); FormUploadToken token = service.FormUpload(entry); HttpContext.Current.Session["form_upload_url"] = token.Url; HttpContext.Current.Session["form_upload_token"] = token.Token; string page = "http://" + Request.ServerVariables["SERVER_NAME"]; if (Request.ServerVariables["SERVER_PORT"] != "80") { page += ":" + Request.ServerVariables["SERVER_PORT"]; } page += Request.ServerVariables["URL"]; HttpContext.Current.Session["form_upload_redirect"] = page; Response.Redirect("UploadVideo.aspx"); } catch (GDataRequestException gdre) { HttpWebResponse response = (HttpWebResponse)gdre.Response; } } }
private IList<Webinar> LoadWebinars() { var service = new YouTubeService("HibernatingRhinosExercise"); var query = new FeedQuery(_uri); var webinars = new List<Webinar>(); AtomFeed result = service.Query(query); if (result != null) { webinars = ParseAtomFeed(result); } return webinars; }
public IList<Webinar> FindWebinars(string keyword) { var service = new YouTubeService("HibernatingRhinosExercise"); var query = new FeedQuery("https://gdata.youtube.com/feeds/api/videos?q={0}" + keyword); var webinars = new List<Webinar>(); AtomFeed result = service.Query(query); if (result != null) { webinars = ParseAtomFeed(result); } return webinars; }
private void loginDone_Click(object sender, EventArgs e) { String key = @"AI39si5BLf_EKytNzPVPtepg-yNDLPSxKOP9ZCBaDTErR5nWmFMy36d8jnKOfwU3PN0c61au0l6b68k9lk7GRluBKh7lvlNRzA"; //My personal API key. YouTubeService service = new YouTubeService("YouTube Synchronizer"); service.setUserCredentials(textLogin.Text, textPassword.Text); //textbox1 contains username and maskedTextBox1 contains password try { service.QueryClientLoginToken(); this.Hide(); } catch (InvalidCredentialsException j) { loginTxt_lbl.Visible = true; } YouTubeRequestSettings settings = new YouTubeRequestSettings("Deprecated", key, textLogin.Text, textPassword.Text); Youtube_Uploader.Properties.Settings.Default.UsernameYT = textLogin.Text; Youtube_Uploader.Properties.Settings.Default.PasswordYT = textPassword.Text; Youtube_Uploader.Properties.Settings.Default.Save(); MainForm.request = new YouTubeRequest(settings); }
private void button1_Click(object sender, EventArgs e) { login = "******"; password = "******"; if (!logged) { YouTubeService service = new YouTubeService("Manager"); service.setUserCredentials(login, password); try { service.QueryClientLoginToken(); } catch (System.Net.WebException ex) { MessageBox.Show(ex.Message); } yousettings = new YouTubeRequestSettings("YTPlayer","AI39si40b25zgBg_U7eheiSnNeb2UMF-3x35HLBYxQDXJEzYOrA8GSQ1vKikFIRSMGOTjBdFvUx4QPz3q72gUkUqOmg9JBx3bQ", login, password); yourequest = new YouTubeRequest(yousettings); logged = true; } YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); query.OrderBy = "viewCount"; query.Query = textBox1.Text; videofeed = yourequest.Get<Video>(query); videofeedcount = videofeed.TotalResults; totalpages = videofeedcount / 25; if (videofeedcount % 25 != 0) totalpages = totalpages + 1; listView1.Items.Clear(); videoIDs.Clear(); foreach (Video entry in videofeed.Entries) { listView1.Items.Add(entry.Title); videoIDs.Add(entry.VideoId); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeRatingsTest() { Tracing.TraceMsg("Entering YouTubeRatingsTest"); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } YouTubeEntry entry = new YouTubeEntry(); entry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime"); entry.Media = new YouTube.MediaGroup(); entry.Media.Description = new MediaDescription("This is a test"); entry.Media.Title = new MediaTitle("Sample upload"); entry.Media.Keywords = new MediaKeywords("math"); // entry.Media.Categories MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); YouTubeEntry newEntry = service.Upload(this.ytUser, entry); Assert.AreEqual(newEntry.Media.Description.Value, entry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, entry.Media.Keywords.Value, "Keywords should be equal"); Rating rating = new Rating(); rating.Value = 1; newEntry.Rating = rating; YouTubeEntry ratedEntry = newEntry.Update(); ratedEntry.Delete(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeInsertTest() { Tracing.TraceMsg("Entering YouTubeFeedTest"); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } GDataRequestFactory factory = service.RequestFactory as GDataRequestFactory; factory.Timeout = 1000000; YouTubeEntry entry = new YouTubeEntry(); entry.MediaSource = new MediaFileSource(this.resourcePath + "test_movie.mov", "video/quicktime"); entry.Media = new YouTube.MediaGroup(); entry.Media.Description = new MediaDescription("This is a test with and & in it"); entry.Media.Title = new MediaTitle("Sample upload"); entry.Media.Keywords = new MediaKeywords("math"); // entry.Media.Categories MediaCategory category = new MediaCategory("Nonprofit"); category.Attributes["scheme"] = YouTubeService.DefaultCategory; entry.Media.Categories.Add(category); YouTubeEntry newEntry = service.Upload(this.ytUser, entry); Assert.AreEqual(newEntry.Media.Description.Value, entry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, entry.Media.Keywords.Value, "Keywords should be equal"); // now change the entry newEntry.Title.Text = "This test upload will soon be deleted"; YouTubeEntry anotherEntry = newEntry.Update() as YouTubeEntry; // bugbug in YouTube server. Returns empty category that the service DOES not like on reuse. so remove ExtensionList a = ExtensionList.NotVersionAware(); foreach (MediaCategory m in anotherEntry.Media.Categories) { if (String.IsNullOrEmpty(m.Value)) { a.Add(m); } } foreach (MediaCategory m in a) { anotherEntry.Media.Categories.Remove(m); } Assert.AreEqual(newEntry.Media.Description.Value, anotherEntry.Media.Description.Value, "Description should be equal"); Assert.AreEqual(newEntry.Media.Keywords.Value, anotherEntry.Media.Keywords.Value, "Keywords should be equal"); // now update the video anotherEntry.MediaSource = new MediaFileSource(this.resourcePath + "test.mp4", "video/mp4"); anotherEntry.Update(); // now delete the guy again newEntry.Delete(); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object using the read only service</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeReadOnlyTest() { Tracing.TraceMsg("Entering YouTubeFeedTest"); YouTubeQuery query = new YouTubeQuery(YouTubeQuery.TopRatedVideo); YouTubeService service = new YouTubeService("NETUnittests"); query.Formats.Add(YouTubeQuery.VideoFormat.RTSP); query.Time = YouTubeQuery.UploadTime.ThisWeek; YouTubeFeed feed = service.Query(query); foreach (YouTubeEntry e in feed.Entries ) { Assert.IsTrue(e.Media.Title.Value != null, "There should be a title"); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube Feed object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeFeedTest() { Tracing.TraceMsg("Entering YouTubeFeedTest"); YouTubeQuery query = new YouTubeQuery(YouTubeQuery.TopRatedVideo); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } query.Formats.Add(YouTubeQuery.VideoFormat.RTSP); query.Time = YouTubeQuery.UploadTime.ThisWeek; YouTubeFeed feed = service.Query(query); foreach (YouTubeEntry e in feed.Entries ) { Assert.IsTrue(e.Media.Title.Value != null, "There should be a title"); } }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube feed, trying to find private videos</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeQueryPrivateTest() { Tracing.TraceMsg("Entering YouTubeQueryPrivateTest"); YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); query.Query = "Education expertvillage"; query.NumberToRetrieve = 50; if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } YouTubeFeed feed = service.Query(query); int counter = 0; foreach (YouTubeEntry e in feed.Entries ) { Assert.IsTrue(e.Media.Title.Value != null, "There should be a title"); if (e.Private == true) { counter++; } } Assert.IsTrue(counter == 0, "counter was " + counter); }
private void btnLogin_Click(object sender, EventArgs e) { var service = new YouTubeService("iSpy", MainForm.Conf.YouTubeKey); service.setUserCredentials(txtYouTubeUsername.Text, txtYouTubePassword.Text); string token = ""; try { token = service.QueryClientLoginToken(); } catch(InvalidCredentialsException) { MessageBox.Show(this, "Login Failed"); } catch(Exception ex) { MessageBox.Show(ex.Message); } if (token != "") MessageBox.Show(this, "Login OK"); }
// constructor public clsVideoFeedReader(string dev_key, string app_name) { _dev_key = dev_key; _app_name = app_name; Service = new YouTubeService(app_name, String.Empty, dev_key); }
private void Login() { ytService = new YouTubeService(APP_NAME, DEV_KEY); ytService.setUserCredentials(USERNAME, PASSWORD); ytRequest = new YouTubeRequest(new YouTubeRequestSettings(APP_NAME,DEV_KEY)); try { LOGIN_TOKEN = ytService.QueryClientLoginToken(); isLoggedIn = LOGIN_TOKEN.Length > 0; if (isLoggedIn) { ProfileEntry profile = (ProfileEntry)ytService.Get(@"https://gdata.youtube.com/feeds/api/users/default"); if (profile == null) return; userProfile.NICKNAME = profile.Firstname + " " + profile.Lastname; userProfile.AGE = "Age: " + profile.Age; userProfile.HOBBIES = "Hobbies: " + profile.Hobbies; userProfile.ID = "ID:" + profile.Id.ToString(); userProfile.HOMETOWN = "Hometown: " + profile.Hometown; userProfile.COMPANY = profile.Company; userProfile.LOCATION = profile.Location; userProfile.RELATIONSHIP = profile.Relationship; userProfile.SCHOOL = profile.School; Statistics statistics = profile.Statistics; if (statistics != null) { userProfile.SUBSCRIBE_COUNT = statistics.SubscriberCount; userProfile.WATCH_COUNT = statistics.WatchCount; userProfile.VIEW_COUNT = statistics.ViewCount; userProfile.FAVORITE_COUNT = statistics.FavoriteCount; } var thumbnail = (from e in profile.ExtensionElements where e.XmlName == "thumbnail" select (XmlExtension)e).SingleOrDefault(); string thumbnailUrl = ""; if (thumbnail != null) { thumbnailUrl = thumbnail.Node.Attributes["url"].Value; } userProfile.AVATAR = thumbnailUrl; } } catch { isLoggedIn = false; } }
// This is function that load video title and url public void tb_KeyDown(Object sender, KeyEventArgs e) { TextBox tmp = (TextBox)sender; if(e.KeyCode == Keys.Enter){ if (tmp.Text == strTmp) { strTmp = ""; player.DocumentText = ""; return; } strTmp = tmp.Text; YouTubeService service = new YouTubeService("MusicTube"); YouTubeQuery query = new YouTubeQuery(); query.StartIndex = 0; query.NumberToRetrieve = 10; query.Uri = new Uri(String.Format("http://gdata.youtube.com/feeds/api/videos?vq={0}", HttpUtility.UrlEncode(tmp.Text)) ); YouTubeFeed feed = service.Query(query); int i = 0; lbx.Items.Clear(); foreach (YouTubeEntry entry in feed.Entries) { MediaGroup group = entry.Media; //タイトルと説明 //Console.WriteLine("Title / {0}", group.Title.Value); //コンテンツ数分ループ foreach (MediaContent content in group.Contents) { SortedList attributes = content.Attributes; //属性数分ループ foreach (DictionaryEntry attribute in attributes) { //Console.WriteLine("Thumbnail key / {0}", attribute.Value + "\n"); if (attribute.Key.Equals("url")) { //サムネイルのURL //Console.WriteLine("Thumbnail key / {0}", attribute.Value + "\n"); strData = (string)attribute.Value; //Console.WriteLine("test:{0}\n", strData.IndexOf("?")); //Console.WriteLine("aaa:\n" + strData); if (strData.IndexOf("?") < 0) { i--; break; } lbx.Items.Add(group.Title.Value); strData = strData.Substring(0, strData.IndexOf("?")); strUrl[i] = strData; //Console.WriteLine("test2:{0}\n", strData); break; } } break; } if (i >= 9) break; i++; } } }
private static void Connect(string username, string password) { if (string.IsNullOrEmpty (username) || string.IsNullOrEmpty (password)) { Log<Youtube>.Error (MissingCredentialsMessage); return; } try { service = new YouTubeService (appName, clientID, developerKey); service.setUserCredentials (username, password); ServicePointManager.CertificatePolicy = new CertHandler (); } catch (Exception e) { Log<Youtube>.Error (ConnectionErrorMessage); Log<Youtube>.Error (e.Message); } }
public static bool TryConnect(string username, string password) { try { service = new YouTubeService (appName, clientID, developerKey); service.setUserCredentials (username, password); Connect (username, password); } catch (Exception) { Log<Youtube>.Error (ConnectionErrorMessage); return false; } return true; }
private void button3_Click(object sender, RoutedEventArgs e) { var service = new YouTubeService("YouTube Synchronizer"); service.setUserCredentials(txtLogin.Text, passwordBox1.Password); try { service.QueryClientLoginToken(); lblBadCredentials.Visibility = Visibility.Hidden; lblLoginSuccess.Visibility = Visibility.Visible; txtLogin.IsEnabled = false; passwordBox1.IsEnabled = false; //Use a validation object here to set the login as good? } catch { lblBadCredentials.Visibility = Visibility.Visible; lblLoginSuccess.Visibility = Visibility.Hidden; } }
///////////////////////////////////////////////////////////////////////////// [Test] public void YouTubeUploaderTest() { YouTubeQuery query = new YouTubeQuery(); query.Uri = new Uri(CreateUri(this.resourcePath + "uploaderyt.xml")); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } YouTubeFeed feed = service.Query(query); YouTubeEntry entry = feed.Entries[0] as YouTubeEntry; YouTube.MediaCredit uploader = entry.Uploader; Assert.IsTrue(uploader != null); Assert.IsTrue(uploader.Role == "uploader"); Assert.IsTrue(uploader.Scheme == "urn:youtube"); Assert.IsTrue(uploader.Value == "GoogleDevelopers"); }
///////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// /// <summary>runs a test on the YouTube factory object</summary> ////////////////////////////////////////////////////////////////////// [Test] public void YouTubeGetActivitiesTest() { ActivitiesQuery query = new ActivitiesQuery(); query.ModifiedSince = new DateTime(1980, 12, 1); YouTubeService service = new YouTubeService("NETUnittests", this.ytClient, this.ytDevKey); if (this.userName != null) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } ActivitiesFeed feed = service.Query(query) as ActivitiesFeed; foreach (ActivityEntry e in feed.Entries ) { Assert.IsTrue(e.VideoId != null, "There should be a videoid"); } service = null; }
private static IEnumerable<Video> LoadVideos(string url) { var youTubeService = new YouTubeService(Factory.GoogleApplicationName); var query = new YouTubeQuery(url); var feed = youTubeService.Query(query); var videos = new List<Video>(); foreach (YouTubeEntry entry in feed.Entries) { var video = Factory.CreateVideo(entry); videos.Add(video); } return videos; }
public override void Initialize(SiteSettings siteSettings) { base.Initialize(siteSettings); orderByList = new Dictionary<String, String>() {{"Relevance", "relevance"}, {"Published", "published"}, {"View Count", "viewCount"}, {"Rating", "rating"}}; foreach (string name in Enum.GetNames(typeof(YouTubeQuery.UploadTime))) timeFrameList.Add(Helpers.StringUtils.ToFriendlyCase(name), name); if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password)) request = new YouTubeRequest(new YouTubeRequestSettings("OnlineVideos", DEVELOPER_KEY)); else request = new YouTubeRequest(new YouTubeRequestSettings("OnlineVideos", DEVELOPER_KEY, login, password)); service = request.Service; service.RequestFactory.UseGZip = true; /*if (!string.IsNullOrEmpty(proxy) && proxyEnabled) { string[] splits = proxy.Split(';'); if (splits.Length > 1) { string[] userPassSplits = splits[1].Split(':'); request.Proxy = new System.Net.WebProxy(splits[0], true, new string[0], new System.Net.NetworkCredential(userPassSplits[0], userPassSplits[1])); } else { request.Proxy = new System.Net.WebProxy(splits[0]); } }*/ }
public clsVideoFeedReader(string DevelopersKey, string ApplicationName, string Username) { _dev_key = DevelopersKey; _app_name = ApplicationName; _username = Username; _yt_service = new YouTubeService(ApplicationName, string.Empty, DevelopersKey); _query_thread.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(_query_thread_RunWorkerCompleted); _query_thread.DoWork += new System.ComponentModel.DoWorkEventHandler(_query_thread_DoWork); }
public void YouTubeUploaderTest() { Tracing.TraceMsg("Entering YouTubeUploaderTest"); YouTubeQuery query = new YouTubeQuery(); query.Uri = new Uri(CreateUri(Path.Combine(this.resourcePath, "uploaderyt.xml"))); YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey); if (!string.IsNullOrEmpty(this.ytUser)) { service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd); } YouTubeFeed feed = service.Query(query); YouTubeEntry entry = feed.Entries[0] as YouTubeEntry; YouTube.MediaCredit uploader = entry.Uploader; Assert.IsTrue(uploader != null); Assert.IsTrue(uploader.Role == "uploader"); Assert.IsTrue(uploader.Scheme == "urn:youtube"); Assert.IsTrue(uploader.Value == "GoogleDevelopers"); }
private YouTubeFeed GetUserVideos(ID id) { YouTubeFeed ytFeed = null; ID parentID = id; if (parentID != (ID)null) { string authorName = GetAuthorName(parentID); if (!string.IsNullOrEmpty(authorName)) { try { YouTubeService ytService = new YouTubeService("Sitecore YouTube Data Provider", GoogleDevKey); // Retrieve only video entries from YouTube service. YouTubeQuery ytQuery = new YouTubeQuery(YouTubeQuery.DefaultVideoUri); ytQuery.Author = authorName; // Set this property to Strict or Moderate to make sure that restricted feeds do not make it into result feed. // Results could also be restricted by setting up Restriction property to an IP address. Only allowed feeds will be retrieved for that IP address. // By default this property is set to caller's IP address. ytQuery.SafeSearch = YouTubeQuery.SafeSearchValues.Strict; ytQuery.NumberToRetrieve = MaxResultsCount; ytFeed = ytService.Query(ytQuery); } catch (Exception ex) { Log.Error(ex.Message, this); } } } return ytFeed; }