* If the service is unable to handle the request.
* @throws IOException error sending request or reading the feed.
*/
private static void searchFeedWithKeywords(YouTubeService service)
throws IOException, ServiceException {
YouTubeQuery query = new YouTubeQuery(new URL(VIDEOS_FEED));
// order the results by the number of views
query.setOrderBy(YouTubeQuery.OrderBy.VIEW_COUNT);
// include restricted content in the search results
query.setSafeSearch(YouTubeQuery.SafeSearch.NONE);
// a category filter holds a collection of categories to limit the search
Query.CategoryFilter categoryFilter = new Query.CategoryFilter();
String keywordTerm = null;
String allKeywords = "";
do {
System.out.println("\nEnter keyword or empty line when done: ");
keywordTerm = readLine();
// creates categories whose scheme is KEYWORD_SCHEME
Category category = new Category(YouTubeNamespace.KEYWORD_SCHEME,
keywordTerm);
categoryFilter.addCategory(category);
// keeps track of concatenated list of keywords entered so far
if(!"".equals(keywordTerm))
allKeywords += keywordTerm + ", ";
} while(keywordTerm != null && !"".equals(keywordTerm));
// adds the collection of keyword categories to the query
query.addCategoryFilter(categoryFilter);
printUnderlined("Running Search for '" + allKeywords + "'");
VideoFeed videoFeed = service.query(query, VideoFeed.class);
for (VideoEntry ve : videoFeed.getEntries()) {
printVideoEntry("", ve, false);