2016-04-14 92 views
1

嘗試從YouTube上檢索用戶評論。下面在java中使用gwt-youtube-api-1.0.3從youtube中提取評論

String videoId = "3u1fu6f8Hto"; 
    String str = "http://gdata.youtube.com/feeds/api/videos/" + videoId + "/comments"; 
    YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(str)); 

    youtubeQuery.setMaxResults(50); 
    youtubeQuery.setStartIndex(1); 

    String videoEntryUrl = youtubeQuery.getUrl().toString(); 

    VideoEntry videoEntry = service.getEntry(new URL(videoEntryUrl), VideoEntry.class); 

    String myUrl = youtubeQuery.getUrl().toString(); // only another name 

    CommentFeed commentFeed = service.getFeed(new URL(myUrl), CommentFeed.class); // Feed response 

代碼代碼給出正顯示出不兼容的類型:URL不能轉換爲字符串

回答

1

爲了取回YouTube留言嘗試執行以下操作:

String commentUrl = videoEntry.getComments().getFeedLink().getHref(); 

CommentFeed commentFeed = service.getFeed(new URL(commentUrl), CommentFeed.class); 
    for(CommentEntry comment : commentFeed.getEntries()) { 
     System.out.println(comment.getPlainTextContent()); 
    } 

這是一個方便的鏈接:https://developers.google.com/youtube/2.0/developers_guide_java#Comments

+0

什麼是videoEntry –