Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get title of YouTube video

What is the easiest way to get the title of a single YouTube video in Android? I'm using the Android YouTube API to play video's but they don't return a title cause it only supports playback options. The only thing I need is to display the title of the video, I obviously have the video ID itself but I don't have a clue where to start.

Things I looked at:

  • YouTube Data API
  • JSOUP(I can see the tag but don't know how to get it)

For some reason I find it hard to understand how to use them and this seems like a really simple action to me. I'm curious if there is an easier option or if there is someone who can help me get on the right track with this.

like image 317
Raymond P Avatar asked Apr 02 '13 14:04

Raymond P


1 Answers

You can use this code for this purpose.

public class SimpleYouTubeHelper {

public static String getTitleQuietly(String youtubeUrl) {
    try {
        if (youtubeUrl != null) {
            URL embededURL = new URL("http://www.youtube.com/oembed?url=" +
                youtubeUrl + "&format=json"
            );

            return new JSONObject(IOUtils.toString(embededURL)).getString("title");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}
}

Source

like image 71
Castiblanco Avatar answered Sep 27 '22 17:09

Castiblanco