1

JAVA を使用して Youtube コンテンツを取得できます。Androidでデータを取得するのを手伝ってください。

Java のコードは次のとおりです。

public class YouTubeTest 
{

public static void main(String[] args) 
    {
   try {
        YouTubeService myService = new YouTubeService("mycompany-myapp-1");

        String myFeed = "http://gdata.youtube.com/feeds/videos?start-index=1&max-results=25&q=earth";

       printVideoFeed(myService, myFeed);
   } 
       catch (IOException ex) {
        Logger.getLogger(YouTubeTest.class.getName()).log(Level.SEVERE, null, ex);
    } 
        catch (ServiceException ex) {
        Logger.getLogger(YouTubeTest.class.getName()).log(Level.SEVERE, null, ex);
    }
}

private static void printVideoFeed(YouTubeService service, String feedUrl) throws IOException, ServiceException {
    VideoFeed videoFeed = service.getFeed(new URL(feedUrl), VideoFeed.class);
    List<VideoEntry> allVideos = videoFeed.getEntries();
    Iterator<VideoEntry> itAllVideos = allVideos.iterator();
    while (itAllVideos.hasNext()){
        VideoEntry oneVideo  = itAllVideos.next();
        TextConstruct oneVideoTitle = oneVideo.getTitle();
        String oneVideoTitleText = oneVideoTitle.getPlainText();

        //Print titles of all videos:
        System.out.print(oneVideoTitleText);

        List<Person> allAuthors = oneVideo.getAuthors();
        Iterator<Person> itAllAuthors = allAuthors.iterator();
        while (itAllAuthors.hasNext()){
            Person oneAuthor = itAllAuthors.next();
            //Print authors of current title:
            System.out.print(" (by " + oneAuthor.getName() +")");
        }
        YtStatistics views= oneVideo.getStatistics();
        System.out.print("\t "+views.getViewCount());

    }
}

}

含めました:mail.jar activation.jar gdata-client-1.0.jar gdata-client-meta-1.0.jar gdata-core-1.0.jar gdata-media-1.0.jar gdata-youtube-1.0.jar gdata- youtube-meta-1.0.jar

Androidで同じコードを試していると、例外が発生します:

FATAL EXCEPTION: main
java.lang.NoClassDefFoundError:com.google.gdata.client.youtube.YouTubeService

        at com.example.youtry.YouTubeTest.abcd(YouTubeTest.java:32)
    at com.example.youtry.MainActivity.onCreate(MainActivity.java:15)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
    at android.app.ActivityThread.access$1500(ActivityThread.java:117)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:123)
    at android.app.ActivityThread.main(ActivityThread.java:3683)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:507)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:839)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)
    at dalvik.system.NativeStart.main(Native Method)

私を助けてください!!!

4

1 に答える 1

1

私の提案は、すべてのタイプのYoutube Vedioeを取得するためにjson Apiを使用でき、簡単に解析して必要な詳細を取得できることです。

好きなタイプが含まれています video String[] MatchItem={"top_rated","top_favorites","most_viewed","most_popular","most_recent"};

// 便利な URL

strUrlmy = "http://gdata.youtube.com/feeds/api/standardfeeds/"+MatchItem[position]+ "? v=2&alt=json";

于 2012-09-06T11:25:57.807 に答える