我现在正在写一篇关于长尾的学士论文,并希望获得数据来研究它的行为。这就是为什么我想检索有关 youtube 视频观看次数的信息。唯一的问题是,一个特定主题(如“most_popular”)的视频提要只有 999 个条目。有没有办法将更多数据检索到特定类别或一般情况下?我将在此处发布我当前的代码(尝试检索“体育”类别的数据):
public static void printVideoEntry(VideoEntry videoEntry, boolean detailed) {
System.out.println("Title: " + videoEntry.getTitle().getPlainText());
if(videoEntry.isDraft()) {
System.out.println("Video is not live");
YtPublicationState pubState = videoEntry.getPublicationState();
if(pubState.getState() == YtPublicationState.State.PROCESSING) {
System.out.println("Video is still being processed.");
}
else if(pubState.getState() == YtPublicationState.State.REJECTED) {
System.out.print("Video has been rejected because: ");
System.out.println(pubState.getDescription());
System.out.print("For help visit: ");
System.out.println(pubState.getHelpUrl());
}
else if(pubState.getState() == YtPublicationState.State.FAILED) {
System.out.print("Video failed uploading because: ");
System.out.println(pubState.getDescription());
System.out.print("For help visit: ");
System.out.println(pubState.getHelpUrl());
}
}
if(videoEntry.getEditLink() != null) {
System.out.println("Video is editable by current user.");
}
if(detailed) {
YtStatistics stats = videoEntry.getStatistics();
if(stats != null ) {
System.out.println("View count: " + stats.getViewCount());
}
System.out.println();
}
}
public static void printVideoFeed(VideoFeed videoFeed, boolean detailed) {
for(VideoEntry videoEntry : videoFeed.getEntries() ) {
printVideoEntry(videoEntry, detailed);
}
}
public static void printEntireVideoFeed(YouTubeService service,
VideoFeed videoFeed, boolean detailed) throws MalformedURLException,
IOException, ServiceException {
do {
printVideoFeed(videoFeed, detailed);
if(videoFeed.getNextLink() != null) {
videoFeed = service.getFeed(new URL(videoFeed.getNextLink().getHref()),
VideoFeed.class);
}
else {
videoFeed = null;
}
}
while(videoFeed != null);
}
public static void main(String[] args) {
try {
YouTubeService service = new YouTubeService("test");
YouTubeQuery query =
new YouTubeQuery(new URL("http://gdata.youtube.com/feeds/api/videos"));
query.setFullTextQuery("Sports");
VideoFeed videoFeed = service.query(query, VideoFeed.class);
printEntireVideoFeed(service, videoFeed, false);
}
catch(AuthenticationException e) {
e.printStackTrace();
}
catch(MalformedURLException e) {
e.printStackTrace();
}
catch(ServiceException e) {
e.printStackTrace();
}
catch(IOException e) {
e.printStackTrace();
}
}