1

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&regionCode=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!

Devesh Kumar Singh
  • 20,259
  • 5
  • 21
  • 40
hoeeeeeh
  • 77
  • 5
  • Your mean youtube not return any data? I have just use `regionCode`=KR. and get some data. – IkarosKun Jan 02 '20 at 04:19
  • they return all channels that can be "seen" in Korea, not channels of Korea. I want to search only Korean channels. – hoeeeeeh Jan 02 '20 at 06:33
  • Oh, I know your means now, And I also not find any for this filter. The parameter of `location` look like only for video, How about use search videos to match channels? – IkarosKun Jan 03 '20 at 05:30
  • I thought about it too, which would be too inefficient because it brings all the videos in one channel. How can I get one video per channel? – hoeeeeeh Jan 06 '20 at 06:10
  • Sorry i have try some methods. but not suit this. – IkarosKun Jan 09 '20 at 02:17
  • @hoeeeeeh if you're interested in this task, you could try what I've described in [my answer](https://stackoverflow.com/a/70497425/12511801). – Marco Aurelio Fernandez Reyes Dec 29 '21 at 19:32

0 Answers0