alaouy / YouTube

🔥 Laravel PHP Facade/Wrapper for the Youtube Data API
MIT License
778 stars 204 forks source link

Get channel ID from vanity URL #187

Closed martindrapeau closed 11 months ago

martindrapeau commented 1 year ago

Youtube channel URLs can now have this format: https://www.youtube.com/@hamontsports

How can we extract the channel ID from the @hamontsports part? Youtube::getChannelByName fails in this case.

ederson13 commented 1 year ago

just came looking for this too

m33ts4k0z commented 1 year ago

You need to search for it first and then process the results. The channelId will exist in the id result object of the response:

$params = [
                'q'             => $channel_name,
                'type'          => 'channel',
                'part'          => 'id, snippet',
                'maxResults'    => 5,
                'order'         => 'title'
            ];

$search = Youtube::searchAdvanced($params); 
silky1284 commented 1 year ago

Keep in mind that search will use up 100 quota points verses 1 for list. So you could easily hit quota limits if you look up to many accounts this way. https://developers.google.com/youtube/v3/determine_quota_cost