How to block specific countries on YouTube Search List from YouTube API?

Viewed 450

I am trying to "block" X country from the search list, but I can't use an operator such as -"X" also I tried some other operators and techniques but none of that worked. I get this Error :

TypeError: bad operand type for unary -: 'str'

I don't know how can I tell YouTube to say I don't want this X, Y, and Z countries on my search list.

here's my code:

import os

import google_auth_oauthlib.flow
import googleapiclient.discovery
import googleapiclient.errors

scopes = ["https://www.googleapis.com/auth/youtube.force-ssl"]

def main():
    # Disable OAuthlib's HTTPS verification when running locally.
    # *DO NOT* leave this option enabled in production.
    os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"

    api_service_name = "youtube"
    api_version = "v3"
    client_secrets_file = "YOUR_CLIENT_SECRET_FILE.json"

    # Get credentials and create an API client
    flow = google_auth_oauthlib.flow.InstalledAppFlow.from_client_secrets_file(
        client_secrets_file, scopes)
    credentials = flow.run_console()
    youtube = googleapiclient.discovery.build(
        api_service_name, api_version, credentials=credentials)

    request = youtube.search().list(
        part="snippet",
        eventType="completed",
        order="videoCount",
        regionCode="X", # X is a country code as an example
        safeSearch="moderate",
        topicId="/m/01k8wb",
        type="video",
        videoDuration="short",
        videoLicense="youtube"
    )
    response = request.execute()

    print(response)

if __name__ == "__main__":
    main()
1 Answers
Related