Get youtube username from channel id
How to get the channel username from using YouTube channel ID?
eg. UCnpaBg-u_kHwzuPyaMcyJ0w is the channel ID for Sony Max
now how to get username "maxindia" from Youtube v3 Api
+3
Vijay C
source
to share
2 answers
When using an API (like developers.google.com ) use part=snippet
and the feed you provided channelTitle
can then be found in one of the objects items/snippet
.
Here's a truncated answer:
{
...
"items": [
{
...
"snippet": {
...
"channelTitle": "maxindia",
...
}
}
}
+2
Thurion
source
to share
Here is a Python solution. It tries to find out channel information from the video ID. Some new channels only have a channel ID and 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)
0
Jabba
source
to share