gpt4 book ai didi

java - 如何仅从 url 获取 YouTube 视频的标题?

转载 作者:行者123 更新时间:2023-12-01 21:14:04 26 4
gpt4 key购买 nike

我正在用java编写一个程序,其中我的程序只给出了youtube视频的url,但我想输出url引用的视频的标题。是否有任何 API 或其他方法可以用来解决这个问题?谢谢。

最佳答案

根据官方youtube api docs 。首先,您需要获取您的 API_KEY。然后点击以下端点(使用 YOUR_API_KEY 和 YOUR_VIDEO_ID)

https://www.googleapis.com/youtube/v3/videos?id=YOUR_VIDEO_ID&key=YOUR_API_KEY
&part=snippet,contentDetails,statistics,status

您将收到一个 JSON 对象作为响应,如下所示

{ 
"kind": "youtube#videoListResponse",
"etag": "\"UCBpFjp2h75_b92t44sqraUcyu0/sDAlsG9NGKfr6v5AlPZKSEZdtqA\"",
"videos": [
{
"id": "7lCDEYXw3mM",
"kind": "youtube#video",
"etag": "\"UCBpFjp2h75_b92t44sqraUcyu0/iYynQR8AtacsFUwWmrVaw4Smb_Q\"",
"snippet": {
"publishedAt": "2012-06-20T22:45:24.000Z",
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"title": "Google I/O 101: Q&A On Using Google APIs",
"description": "Antonio Fuentes speaks to us and takes questions on working with Google APIs and OAuth 2.0.",
"thumbnails": {
"default": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/default.jpg"
},
"medium": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/mqdefault.jpg"
},
"high": {
"url": "https://i.ytimg.com/vi/7lCDEYXw3mM/hqdefault.jpg"
}
},
"categoryId": "28"
},
"contentDetails": {
"duration": "PT15M51S",
"aspectRatio": "RATIO_16_9"
},
"statistics": {
"viewCount": "3057",
"likeCount": "25",
"dislikeCount": "0",
"favoriteCount": "17",
"commentCount": "12"
},
"status": {
"uploadStatus": "STATUS_PROCESSED",
"privacyStatus": "PRIVACY_PUBLIC"
}
}
]
}

您可以获得所有信息,包括标题。

关于java - 如何仅从 url 获取 YouTube 视频的标题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58887025/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com