我正在为我的项目使用YouTube Data API v3,我想知道是否通过这个API调用:
https://www.googleapis.com/youtube/v3/commentThreads?key=YOUR_KEY&textFormat=plainText&part=snippet&maxResults=5&order=relevance&videoId=YOUR_ID
,
我能不能得到那个视频的标题?
这是我从API获得的:
{
"kind": "youtube#commentThreadListResponse",
"etag": "KcqDjUnisqZz_7Kr1dfxHxM4jSM",
"nextPageToken": "QURTSl9pMUxESzFEZk53RV9nNnUzRWx6S2VQY1A5QVpPS2JrZUltdnl2MzhidmM4bzRaY1ZTa1ZzaXBQbGdiYWd0LXRvc1lTVzJQSHdnLXdKRW11MzlDMHp1WGpFS1dCVEczb0hXZ3JhcEQ0b3FnVlprb1duRUJTWVh1d0J1dzVJdw==",
"pageInfo": {
"totalResults": 5,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#commentThread",
"etag": "h3h5DKe5ApoaVan5iX4vC2glnYA",
"id": "Ugxxqkvik0jDB9_WSth4AaABAg",
"snippet": {
"videoId": "8juRm9I__uk",
"topLevelComment": {
"kind": "youtube#comment",
"etag": "pjDNsBFra34PxM9VOQtI49R9-_Y",
"id": "Ugxxqkvik0jDB9_WSth4AaABAg",
"snippet": {
"videoId": "8juRm9I__uk",
"textDisplay": "Nyesel beli realme 3 pro ",
"textOriginal": "Nyesel beli realme 3 pro ",
"authorDisplayName": "Dodi Satria",
"authorProfileImageUrl": "https://yt3.ggpht.com/ytc/AAUvwnir7Yxd0qmDbKtLo568c7RKbDQvGlFeq_LjlGxM4A=s48-c-k-c0xffffffff-no-rj-mo",
"authorChannelUrl": "http://www.youtube.com/channel/UC28fGIqdC7B1y5BRVhmI8Eg",
"authorChannelId": {
"value": "UC28fGIqdC7B1y5BRVhmI8Eg"
},
"canRate": true,
"viewerRating": "none",
"likeCount": 3,
"publishedAt": "2019-08-01T11:52:39Z",
"updatedAt": "2019-08-01T11:52:39Z"
}
},
"canReply": true,
"totalReplyCount": 1,
"isPublic": true
}
},
视频ID在那里,但我能得到视频的标题吗?
正如@DaImTo在上面的评论中建议的那样,您需要调用Videos.list
API端点来获取与您感兴趣的视频相对应的元数据信息。
以下是一个通用URL,当在GET
HTTP方法上发布时,它会调用Videos.list
:
https://www.googleapis.com/youtube/v3/videos?key=YOUR_API_KEY&part=snippet&fields=items/snippet/title&id=YOUR_VIDEO_ID
。
请注意,上面我使用的fields
请求参数仅从API获取实际需要的信息。
例如,在id
为bKINwXXzlaQ
的情况下,端点返回以下JSON响应文本:
{
"items": [
{
"snippet": {
"title": "The European semiconductor industry and its global competition | DW News"
}
}
]
}