获取 YouTube 视频的标题 [英] Get title of YouTube video

查看:29
本文介绍了获取 YouTube 视频的标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Android 中获取单个 YouTube 视频标题的最简单方法是什么?我正在使用 Android YouTube API 播放视频,但它们不返回标题,因为它仅支持播放选项.我唯一需要的是显示视频的标题,我显然有视频 ID 本身,但我不知道从哪里开始.

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.

我看过的东西:

  • YouTube 数据 API
  • JSOUP(我可以看到标签,但不知道如何获取)

出于某种原因,我发现很难理解如何使用它们,这对我来说似乎是一个非常简单的操作.我很好奇是否有更简单的选择,或者是否有人可以帮助我走上正轨.

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.

推荐答案

您可以将此代码用于此目的.

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;
}
}

来源

这篇关于获取 YouTube 视频的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆