如何通过YouTube API获取YouTube视频的标题 [英] How to get the title of YouTube video through the YouTube API
问题描述
我有一个YouTube视频的布局.我想设置视频的缩略图和标题. (我成功设置了缩略图,但没有设置标题)
I've the layout for a YouTube video. I would like to set the video's Thumbnail and Title. (I succeeded to set the thumbnail but not the title)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="1.0">
<com.google.android.youtube.player.YouTubeThumbnailView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="6dp"
android:layout_marginTop="10dp"
android:id="@+id/youtubeThumbnailView"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="YouTube Video"
android:textSize="20sp"
android:layout_marginLeft="4dp"
android:layout_marginTop="10dp"
android:layout_gravity="center"
android:id="@+id/textViewTitle"/>
</LinearLayout>
我在此处设置了缩略图:
I set the Thumbnail here:
YouTubeThumbnailView youTubeThumbnailView = (YouTubeThumbnailView) newChild.findViewById(R.id.youtubeThumbnailView);
youTubeThumbnailView.initialize(YouTubePlayer.DEVELOPER_KEY, new YouTubeThumbnailView.OnInitializedListener() {
@Override
public void onInitializationSuccess(YouTubeThumbnailView youTubeThumbnailView, final YouTubeThumbnailLoader youTubeThumbnailLoader) {
youTubeThumbnailLoader.setVideo("FM7MFYoylVs");
youTubeThumbnailLoader.setOnThumbnailLoadedListener(new YouTubeThumbnailLoader.OnThumbnailLoadedListener() {
@Override
public void onThumbnailLoaded(YouTubeThumbnailView youTubeThumbnailView, String s) {
youTubeThumbnailLoader.release();
}
@Override
public void onThumbnailError(YouTubeThumbnailView youTubeThumbnailView, YouTubeThumbnailLoader.ErrorReason errorReason) {
}
});
}
@Override
public void onInitializationFailure(YouTubeThumbnailView youTubeThumbnailView, YouTubeInitializationResult youTubeInitializationResult) {
}
});
如何从视频中获取标题?
我在这里看到了一个解决方案:获取YouTube视频的标题
I saw a solution here: Get title of YouTube video
但是我不确定这是否正确.我猜想YouTube API使我们可以更轻松地获取标题,例如:youTubeThumbnailView.getText().
but I'm not sure if this is the correct way. I guess that YouTube API lets us get the title in an easier way such as: youTubeThumbnailView.getText() for example.
推荐答案
您可以使用google api来获取它:https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet&id=YOUR_VIDEO_ID&key=KEY
you can get it by using google api as : https://www.googleapis.com/youtube/v3/videos?part=id%2C+snippet&id=YOUR_VIDEO_ID&key=KEY
这篇关于如何通过YouTube API获取YouTube视频的标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!