Youtube api YouTube API v3-列出上传的视频
如何在V3 api中列出用户上传的视频?第一步是获取该用户的频道id。我们可以通过请求Youtube api YouTube API v3-列出上传的视频,youtube-api,youtube-data-api,Youtube Api,Youtube Data Api,如何在V3 api中列出用户上传的视频?第一步是获取该用户的频道id。我们可以通过请求频道服务来实现这一点。下面是一个JS示例 var request = gapi.client.youtube.channels.list({ // mine: true indicates that we want to retrieve the channel for the authenticated user. mine: true, part: 'contentDetails' }); re
频道
服务来实现这一点。下面是一个JS示例
var request = gapi.client.youtube.channels.list({
// mine: true indicates that we want to retrieve the channel for the authenticated user.
mine: true,
part: 'contentDetails'
});
request.execute(function(response) {
playlistId = response.result.channels[0].contentDetails.uploads;
});
获得播放列表id后,我们可以使用该id从playlitems
服务中查询上传的视频列表
var request = gapi.client.youtube.playlistItems.list({
playlistId: playlistId,
part: 'snippet',
});
request.execute(function(response) {
// Go through response.result.playlistItems to view list of uploaded videos.
});
如果您使用的是客户端,那么Greg的回答是正确的。要对基本请求执行相同的操作,请执行以下2个请求:
part=contentDetails
mine=true
key={YOUR_API_KEY}
part=snippet
maxResults=50
playlistId={YOUR_UPLOAD_PLAYLIST_ID}
key={YOUR_API_KEY}
和标题:
Authorization: Bearer {Your access token}
由此,您将得到如下JSON响应:
{
"kind": "youtube#channelListResponse",
"etag": "\"some-string\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "some-id",
"kind": "youtube#channel",
"etag": "\"another-string\"",
"contentDetails": {
"relatedPlaylists": {
"likes": "channel-id-for-your-likes",
"favorites": "channel-id-for-your-favorites",
"uploads": "channel-id-for-your-uploads",
"watchHistory": "channel-id-for-your-watch-history",
"watchLater": "channel-id-for-your-watch-later"
}
}
}
]
}
由此,您需要解析出“上传”通道idpart=contentDetails
mine=true
key={YOUR_API_KEY}
part=snippet
maxResults=50
playlistId={YOUR_UPLOAD_PLAYLIST_ID}
key={YOUR_API_KEY}
和标题:
Authorization: Bearer {YOUR_TOKEN}
您将从中收到一个JSON响应,如下所示:
{
"kind": "youtube#playlistItemListResponse",
"etag": "\"some-string\"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 50
},
"items": [
{
"id": "some-id",
"kind": "youtube#playlistItem",
"etag": "\"another-string\"",
"snippet": {
"publishedAt": "some-date",
"channelId": "the-channel-id",
"title": "video-title",
"thumbnails": {
"default": {
"url": "thumbnail-address"
},
"medium": {
"url": "thumbnail-address"
},
"high": {
"url": "thumbnail-address"
}
},
"playlistId": "upload-playlist-id",
"position": 0,
"resourceId": {
"kind": "youtube#video",
"videoId": "the-videos-id"
}
}
}
]
}
使用此方法,您应该能够使用任何语言甚至仅使用curl获取信息。如果您想要的结果超过前50个,则必须使用第二个请求执行多个查询,并传入页面请求。有关这方面的更多信息,请访问:使用mine参数列出频道/播放列表,但我找不到列出频道视频的方法。
。list
方法不会返回。我有两个简单的日志,在调用方法之前和之后,第一个执行,第二个不执行。有什么想法吗?你能举例说明你在做什么吗?@pratikchoshi使用@bottomlook来演示。我通过:产生“上传”:“UUhS0SPpEqGMGRim7mebedPg”。@我现在做的是:。。。糟糕的是内容长度没有被包括在内。你可以在视频中找到像“duration”这样的内容细节:“PT7M18S”;我希望它没有这种疯狂的每视频查询,就连贯的实现而言,我计划从v2升级到v3(因为我不得不这么做)。所以当你点击这个时,它将是v3;这真的帮了我大忙!如果有帮助,以下是“上传”频道ID的文档: