'Youtube Api, Get video url with given id channel and title of video
I need id of video for example https://www.youtube.com/watch?v=wIN0tTy-Jmg
the id which I need is wIN0tTy-Jmg
but it returns only 50 videos and sometimes I can't get video which has title that I need
I need only one video id, I know title and given channel ID
How to get this id? Any ideas?
Solution 1:[1]
The youtube api does not have a video get method. So there is no way to directly get just a single video.
I am not sure why you are using the activites.list method.
I would use a search.list and send the channel id. example
request
GET https://www.googleapis.com/youtube/v3/search?part=snippet&channelId=UCWnY0GoKFnFY0oeaEN605Ug&maxResults=50&key={YOUR_API_KEY}
response
{
"kind": "youtube#searchListResponse",
"etag": "\"XI7nbFXulYBIpL0ayR_gDh3eu1k/9HyOjSMVnKv1vm239plm060CuiY\"",
"nextPageToken": "CDIQAA",
"regionCode": "DK",
"pageInfo": {
"totalResults": 71,
"resultsPerPage": 50
},
...
}
It is still returning more then the max 50 rows. You are going to have to use the next page token to get the next page of results.
Solution 2:[2]
The video url is not direct in the response, but you can get is since the thunbnail url has the part you need. Eg:
'thumbnails': {'default': {'url': 'https://i.ytimg.com/vi/k6MAcJLxE1I/default.jpg', ...
actual video: https://www.youtube.com/watch?v=k6MAcJLxE1I
so, when you get the response from the playlist, the url will be
'https://www.youtube.com/watch?v=' + response["items"][0]['snippet']['thumbnails']["standard"]["url"].split("/")[-2]
where 0 is the first video of the list and so on
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DaImTo |
Solution 2 | Gustavo Voltani von Atzingen |