适用于 Android 的 YouTube gdata API

发布于 2024-11-29 09:40:35 字数 8816 浏览 0 评论 0 原文

我可以使用 Java YouTube 数据 API jar 在 Android 中开发 YouTube 应用程序吗?

我尝试集成该 jar。 但是当我运行时它显示异常

class def not found for YouTubeService

有时它显示

class def not found for MediaSource

这是我测试的示例程序。我想打印查询后获得的列表的大小。

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    service = new YouTubeService("myService");
    urlString = "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated";
    try {
        videoFeed = service.getFeed(new URL(urlString), VideoFeed.class);
        videoEntries = videoFeed.getEntries();
        System.out.println("List Size"+videoEntries.size());


    } catch (MalformedURLException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    } catch (ServiceException e) {

        e.printStackTrace();
    }



}

现在它显示以下错误。

09-03 16:27:38.844: WARN/XmlParser(387): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:38.844: WARN/XmlParser(387): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:38.844: WARN/XmlParser(387):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.data.BaseFeed.parseAtom(BaseFeed.java:867)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:1136)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:998)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:1017)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.mcet.youtube.YoutubeActivity.onCreate(YoutubeActivity.java:38)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.os.Looper.loop(Looper.java:123)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 16:27:38.844: WARN/XmlParser(387):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 16:27:38.844: WARN/XmlParser(387):     at java.lang.reflect.Method.invoke(Method.java:521)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 16:27:38.844: WARN/XmlParser(387):     at dalvik.system.NativeStart.main(Native Method)
09-03 16:27:38.997: WARN/System.err(387): com.google.gdata.util.ParseException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:708)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.data.BaseFeed.parseAtom(BaseFeed.java:867)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:1136)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:998)
09-03 16:27:39.044: WARN/System.err(387):     at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
09-03 16:27:39.044: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:1017)
09-03 16:27:39.044: WARN/System.err(387):     at com.mcet.youtube.YoutubeActivity.onCreate(YoutubeActivity.java:38)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-03 16:27:39.064: WARN/System.err(387):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-03 16:27:39.064: WARN/System.err(387):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-03 16:27:39.064: WARN/System.err(387):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 16:27:39.074: WARN/System.err(387):     at android.os.Looper.loop(Looper.java:123)
09-03 16:27:39.074: WARN/System.err(387):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 16:27:39.074: WARN/System.err(387):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 16:27:39.084: WARN/System.err(387):     at java.lang.reflect.Method.invoke(Method.java:521)
09-03 16:27:39.084: WARN/System.err(387):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 16:27:39.084: WARN/System.err(387):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 16:27:39.084: WARN/System.err(387):     at dalvik.system.NativeStart.main(Native Method)
09-03 16:27:39.095: WARN/System.err(387): Caused by: javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:39.095: WARN/System.err(387):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
09-03 16:27:39.095: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
09-03 16:27:39.095: WARN/System.err(387):     ... 28 more

Can I use Java YouTube data API jar for developing YouTube Application in Android

I tried integrating the jar.
But when I run it is showing Exception

class def not found for YouTubeService

Sometimes it shows

class def not found for MediaSource

This is the sample program that I tested. I want to print the size of the list obtained after the query.

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);


    service = new YouTubeService("myService");
    urlString = "http://gdata.youtube.com/feeds/api/standardfeeds/top_rated";
    try {
        videoFeed = service.getFeed(new URL(urlString), VideoFeed.class);
        videoEntries = videoFeed.getEntries();
        System.out.println("List Size"+videoEntries.size());


    } catch (MalformedURLException e) {

        e.printStackTrace();
    } catch (IOException e) {

        e.printStackTrace();
    } catch (ServiceException e) {

        e.printStackTrace();
    }



}

Now it is showing the following error.

09-03 16:27:38.844: WARN/XmlParser(387): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:38.844: WARN/XmlParser(387): javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:38.844: WARN/XmlParser(387):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.data.BaseFeed.parseAtom(BaseFeed.java:867)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:1136)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:998)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.google.gdata.client.Service.getFeed(Service.java:1017)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.mcet.youtube.YoutubeActivity.onCreate(YoutubeActivity.java:38)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.os.Looper.loop(Looper.java:123)
09-03 16:27:38.844: WARN/XmlParser(387):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 16:27:38.844: WARN/XmlParser(387):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 16:27:38.844: WARN/XmlParser(387):     at java.lang.reflect.Method.invoke(Method.java:521)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 16:27:38.844: WARN/XmlParser(387):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 16:27:38.844: WARN/XmlParser(387):     at dalvik.system.NativeStart.main(Native Method)
09-03 16:27:38.997: WARN/System.err(387): com.google.gdata.util.ParseException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:708)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:576)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.data.BaseFeed.parseAtom(BaseFeed.java:867)
09-03 16:27:39.005: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:68)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDataParser.parse(AtomDataParser.java:39)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.CharacterParser.parse(CharacterParser.java:100)
09-03 16:27:39.014: WARN/System.err(387):     at com.google.gdata.wireformats.input.XmlInputParser.parse(XmlInputParser.java:52)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:66)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.wireformats.input.AtomDualParser.parse(AtomDualParser.java:34)
09-03 16:27:39.025: WARN/System.err(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2165)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.parseResponseData(Service.java:2098)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:1136)
09-03 16:27:39.035: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:998)
09-03 16:27:39.044: WARN/System.err(387):     at com.google.gdata.client.GoogleService.getFeed(GoogleService.java:631)
09-03 16:27:39.044: WARN/System.err(387):     at com.google.gdata.client.Service.getFeed(Service.java:1017)
09-03 16:27:39.044: WARN/System.err(387):     at com.mcet.youtube.YoutubeActivity.onCreate(YoutubeActivity.java:38)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
09-03 16:27:39.054: WARN/System.err(387):     at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
09-03 16:27:39.064: WARN/System.err(387):     at android.app.ActivityThread.access$2300(ActivityThread.java:125)
09-03 16:27:39.064: WARN/System.err(387):     at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
09-03 16:27:39.064: WARN/System.err(387):     at android.os.Handler.dispatchMessage(Handler.java:99)
09-03 16:27:39.074: WARN/System.err(387):     at android.os.Looper.loop(Looper.java:123)
09-03 16:27:39.074: WARN/System.err(387):     at android.app.ActivityThread.main(ActivityThread.java:4627)
09-03 16:27:39.074: WARN/System.err(387):     at java.lang.reflect.Method.invokeNative(Native Method)
09-03 16:27:39.084: WARN/System.err(387):     at java.lang.reflect.Method.invoke(Method.java:521)
09-03 16:27:39.084: WARN/System.err(387):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
09-03 16:27:39.084: WARN/System.err(387):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
09-03 16:27:39.084: WARN/System.err(387):     at dalvik.system.NativeStart.main(Native Method)
09-03 16:27:39.095: WARN/System.err(387): Caused by: javax.xml.parsers.ParserConfigurationException: org.xml.sax.SAXNotRecognizedException: http://xml.org/sax/features/external-parameter-entities
09-03 16:27:39.095: WARN/System.err(387):     at org.apache.harmony.xml.parsers.SAXParserFactoryImpl.newSAXParser(SAXParserFactoryImpl.java:84)
09-03 16:27:39.095: WARN/System.err(387):     at com.google.gdata.util.XmlParser.parse(XmlParser.java:682)
09-03 16:27:39.095: WARN/System.err(387):     ... 28 more

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

在巴黎塔顶看东京樱花 2024-12-06 09:40:35

我不完全确定(你的问题可能更清楚一点?),但我认为你遇到的问题是你需要 JavaMail 的 Android 端口,可以在 此处。将现有的mail.jar 和activation.jar 替换为其中找到的两个,并添加additional.jar。这有望解决您的问题。

如果没有,请添加您的 LogCat 输出以及有关错误的更多详细信息,我将尽力提供进一步帮助。

I'm not entirely sure (your question could be a little clearer?) but I think the problem you're having is that you need to Android port of JavaMail, which can be found here. Replace your existing mail.jar and activation.jar with the two found there, and add the additionnal.jar also. This should hopefully sort out your problem.

If not, please add your LogCat output and a bit more detail about the error and I'll try to help further.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文