0

我正在尝试检索前 50 条评论,这是代码:

package com.youtube;

import java.net.URL;
import com.google.gdata.client.youtube.YouTubeQuery;
import com.google.gdata.client.youtube.YouTubeService;
import com.google.gdata.data.youtube.CommentFeed;
import com.google.gdata.data.youtube.VideoEntry;

public class Ex_Y1

{

public static void main(String args[]) throws Exception
{
      YouTubeService service = new YouTubeService("MyApp");

    String str = "http://gdata.youtube.com/feeds/api/videos/" + 1000;

    YouTubeQuery youtubeQuery = new YouTubeQuery(new URL(str));

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

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

    if (videoEntry.getComments() != null) {
        String commentUrl = videoEntry.getComments().getFeedLink().getHref();
        System.out.println(commentUrl);

        YouTubeQuery youtubeQuery1 = new YouTubeQuery(new URL(commentUrl));
        youtubeQuery1.setMaxResults(50);


        youtubeQuery.setStartIndex(1);
        String commentUrlFeed = youtubeQuery.getUrl().toString();
        CommentFeed commentFeed = service.getFeed(new URL(commentUrlFeed),CommentFeed.class);

        for (int i = 0; i < commentFeed.getEntries().size()
                && commentFeed.getEntries().get(i) != null; i++) {

            String author=commentFeed.getEntries().get(i).getAuthors().get(0).getUri().substring(41);
            String commentId=commentFeed.getEntries().get(i).getId().substring(47);
            String comment=commentFeed.getEntries().get(i).getPlainTextContent();

            System.out.print(author);
            System.out.print(commentId);
            System.out.print(comment);
            }
        }

     }

}

但是发生了这个错误:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
    at com.youtube.Ex_Y1.main(Ex_Y1.java:16)

Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException

at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 1 more
4

1 回答 1

1

不要使用 google-collect-1.0 jar 文件。取而代之的是guava-10.0.1.jar

于 2013-10-01T14:56:48.607 回答