How to get the username of the channel from using the youtube channel id ?
E.g. UCnpaBg-u_kHwzuPyaMcyJ0w is the Channel ID for Sony Max
now how to get username "maxindia" from Youtube v3 Api
Here is a Python solution. It tries to find out the channel info from the video ID. Some newer channels only have a channel ID and no username.
import requests
API_KEY = "..."
def get_channel_id(vid):
url = "https://www.googleapis.com/youtube/v3/videos?id={vid}&key={api_key}&part=snippet".format(
vid=vid, api_key=API_KEY
)
d = requests.get(url).json()
return d['items'][0]['snippet']['channelId']
def get_channel_title(cid):
url = "https://www.googleapis.com/youtube/v3/search?part=snippet&channelId={cid}&key={api_key}".format(
cid=cid, api_key=API_KEY
)
d = requests.get(url).json()
return d['items'][0]['snippet']['channelTitle']
def main():
video_id = "..."
channel_id = get_channel_id(video_id)
channel_title = get_channel_title(channel_id)
print(channel_id)
print(channel_title)
When using the API (for example on developers.google.com), use part=snippet
and the channelId you provided, then the channelTitle
can be found in one of the items/snippet
objects.
Here is the truncated response:
{
...
"items": [
{
...
"snippet": {
...
"channelTitle": "maxindia",
...
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With