String fields = "@gd:etag,media:group/media:keywords";
Query query = new Query(entryUrl);
query.setFields(fields);
// Get representation for the interested fields
VideoEntry videoEntry = null;
try {
videoEntry = service.getEntry(query.getUrl(), VideoEntry.class);
} catch (ServiceException se) {
// an invalid video ID was used.
}
if (videoEntry == null) {
output.println("Sorry, the video ID you entered was not valid.\n");
return;
}
output.println("Current Keywords: "
+ videoEntry.getMediaGroup().getKeywords().getKeywords());
// add a new keyword
output.println("Specify a keyword to add: ");
String keyword = readLine();
videoEntry.getMediaGroup().getKeywords().addKeyword(keyword);
VideoEntry updatedEntry = service.patch(entryUrl, fields, videoEntry);
output.println("Keywords after update: "
+ updatedEntry.getMediaGroup().getKeywords().getKeywords());
}