YouTube Java API problems

假如想象 提交于 2019-12-12 11:22:36

问题


I'm trying to get a list of videos by a certain user using the YouTube Java GData library/API.

However, when I try to create a service by using YouTubeService service = new YouTubeService("Cyphon-MyCampusPulse-1", YOUTUBE_API_KEY);, I get the following runtime exception:

Exception in thread "main" java.lang.NoClassDefFoundError: javax/mail/MessagingException
at scrapers.YouTubePulseScraper.<init>(YouTubePulseScraper.java:37)
at scrapers.YouTubePulseScraper.main(YouTubePulseScraper.java:153)
Caused by: java.lang.ClassNotFoundException: javax.mail.MessagingException
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 2 more

I'm not sure how the exception relates to what I'm doing. Any hints are appreciated.


回答1:


You need to add the JavaMail jar to your classpath, which contains javax.mail.MessagingException. You can get it here: http://www.oracle.com/technetwork/java/index-138643.html

Edit: Extracted from the documentation:

The GData Java Client Library has the following external dependencies. The following sections will describe how to install these dependencies on your favorite operating system (or the OS that you're stuck with at work).

  • JDK (Java Development Kit) version 1.5+
  • Apache Ant version 1.7+
  • mail.jar in Sun's JavaMail API 1.4+
  • activation.jar in Sun's JavaBeansActivationFramewrok. This is only required for media specific APIs including Document List Data API, Picasa Web Album API, and YouTube Data API.
  • servlet.jar in Sun's Servlet API version 2.3+. This is required only if executing code samples in 'sample.authsub' or 'sample.gbase.recipe' packages.

A few of the .jar dependencies are only required for specific samples, but to avoid build errors, it's best just to get everything. Choose your operating system of choice to continue: Windows, Mac OS X, or Linux.

I've added this since if you're missing one dependency you might be missing others, so you should double check you have everything.




回答2:


You need Java Mail, which is available from Maven Repository:

<dependency>
  <groupId>javax.mail</groupId>
  <artifactId>mail</artifactId>
  <version>1.4.5</version>
</dependency>


来源:https://stackoverflow.com/questions/3510479/youtube-java-api-problems

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!