I want to search a youTube channel in specific country (by using channel info)
I'm using python 3.7, and YouTube Search API v3.
I already used regionCode
, relevanceLanguage
, location
and Radius
with video but it doesn't work.
I think the result of regionCode seems to include all the content that can be seen in a particular country. Also relevanceLanguage
seems like 'just related with specific language'.
How can I solve this problem?
this is the code I've already done
def youtube_search(options, limit):
youtube = build(YOUTUBE_API_SERVICE_NAME, YOUTUBE_API_VERSION,
developerKey=DEVELOPER_KEY)
# GET https://www.googleapis.com/youtube/v3/channels
search_response = youtube.search().list(
type="channel",
part="snippet",
order="viewCount",
regionCode="KR",
relevanceLanguage="KO",
# location="36.580614, 127.976353",
# locationRadius="400km",
maxResults=50,
pageToken=options.nextPageToken
).execute()
# print(search_response)
# GET https://www.googleapis.com/youtube/v3/search/?order=date®ionCode=KR&type&channel&part=snippet&maxResults=50&pageToken=somePageToken
channels = []
sub = []
channelTitles = []
options.nextPageToken = search_response.get("nextPageToken")
for search_result in search_response.get("items", []):
channelTitles.append("%s" % (search_result["snippet"]["channelTitle"]))
print(search_result["snippet"]["channelTitle"])
if search_result["id"]["kind"] == "youtube#channel":
sub.append("%s" % (search_result["snippet"]["title"]))
channels.append("%s" % (search_result["id"]["channelId"]))
idx = 0
for channelid in channels:
search_response = youtube.channels().list(
part="snippet",
id=channelid,
maxResults="1",
).execute()
# GET https://www.googleapis.com/youtube/v3/channels/part=statistics&id=channelid&maxResults=1
for search_ret in search_response.get("items", []):
print(channelTitles[idx])
idx = idx + 1
limit = limit + 1
if limit < 5:
youtube_search(options, limit)
if __name__ == "__main__":
argparser.add_argument("--nextPageToken", help="Max results", default="")
args = argparser.parse_args()
try:
youtube_search(args, 2)
except HttpError as e:
print("An HTTP error %d occurred:\n%s" % (e.resp.status, e.content))
happy new year!