我使用YouTube API 3.0,希望按作者搜索视频。我该如何做到这一点?
我使用的是python客户端库。
在YouTube Data API v3中,您需要从用户的频道中找到UploadsPlaylist,然后他们查找该频道的PlaylistItems。
例如,如果你想找到GoogleDevelopers上传的内容,首先要找到他们的channel_id。
如果你不知道用户的channel_id,你必须调用搜索资源(种类设置为"channel")才能找到它:
https://www.googleapis.com/youtube/v3/search?part=id&maxResults=1&q=谷歌开发者&type=通道&密钥={YOUR_API_key}
退货:
{
"kind": "youtube#searchListResponse",
"etag": ""Sja0zsjNVqBAv0D_Jpz6t1GyTzk/fm4P2RLxOAO0xdASI5BagD86H8A"",
"pageInfo": {
"totalResults": 21,
"resultsPerPage": 1
},
"nextPageToken": "CAEQAA",
"items": [
{
"id": {
"kind": "youtube#channel",
"channelId": "UC_x5XG1OV2P6uZZ5FSM9Ttw"
},
"kind": "youtube#searchResult",
"etag": ""Sja0zsjNVqBAv0D_Jpz6t1GyTzk/q4hYefapiMoagc7b_3bYaVZvSJo""
}
]
}
正如你所看到的,他们的channelId=UC_x5XG1OV2P6uZZ5FSM9TW
调用频道资源的contentDetais部分以查找其上传播放列表:
https://www.googleapis.com/youtube/v3/channels?part=contentDetails&id=UC_x5XG1OV2P6uZZ5FSM9TW&密钥={YOUR_API_key}
哪个会返回这个:
{
"kind": "youtube#channelListResponse",
"etag": ""Sja0zsjNVqBAv0D_Jpz6t1GyTzk/ZouMU1qBRkF6DgacOLHE88Xk144"",
"pageInfo": {
"totalResults": 1,
"resultsPerPage": 1
},
"items": [
{
"id": "UC_x5XG1OV2P6uZZ5FSM9Ttw",
"kind": "youtube#channel",
"etag": ""Sja0zsjNVqBAv0D_Jpz6t1GyTzk/khrrkvk8Tl0XWRZoN66zqloSJM4"",
"contentDetails": {
"relatedPlaylists": {
"uploads": "UU_x5XG1OV2P6uZZ5FSM9Ttw"
}
}
}
]
}
正如你所看到的,他们上传的播放列表id是UU_x5XG1OV2P6uZZ5FSM9TW
调用PlaylistItems资源以获取GoogleDevelopers上传的视频:
https://www.googleapis.com/youtube/v3/playlistItems?part=id%2Csnippet%2CcontentDetails&playlistId=UU_x5XG1OV2P6uZZ5FSM9TW&密钥={YOUR_API_key}