I18nRegions

Learn about the different geographic areas that users can select as preferred content regions.

What is the i18nRegion resource?

Users can set certain geographic areas as their preferred region on YouTube, filtering the content shown to them based on region. The details regarding these regions, including a region code and name, are stored in the i18nRegion resource. The region code in this resource can be passed as the regionCode parameter when making specific API calls, such as the videos.list, search.list, or activities.list methods, effectively filtering the results based on region.

Supported methods

The API supports only the list method, which returns a list of content regions supported by YouTube for this resource.

Let’s look at an example to retrieve a list of these content regions where YouTube is available.

Press + to interact
api_service_name = "youtube"
api_version = "v3"
DEVELOPER_KEY = "{{API_KEY}}"
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey = DEVELOPER_KEY)
request = youtube.i18nRegions().list(
part="snippet"
)
response = request.execute()

The JSON response returns a list of objects, where each object has the snippet part associated with each region. Each object represents information about a region, including the id and name of the region.

Example: Retrieving videos from a region

The following example uses the search resource and the list method to retrieve the first 25 videos associated with a particular keyword in the US region.

We require a keyword and region code to retrieve results associated with them. You can replace the parameter q (at line 10) in the code below. To do so, click the “Edit” button in the following widget, enter the keyword and region code in the KEYWORD field, respectively and click the “Save” button.

Note: The KEYWORD has a default value that can be changed by following the steps discussed above. We have also used the fields parameter to filter the response.

Run the following code to get a response with information about the video.

Press + to interact
api_service_name = "youtube"
api_version = "v3"
DEVELOPER_KEY = "{{API_KEY}}"
youtube = googleapiclient.discovery.build(
api_service_name, api_version, developerKey = DEVELOPER_KEY)
request = youtube.search().list(
part="snippet",
q="{{KEYWORD}}",
regionCode="US",
maxResults=25,
type="video",
fields="kind,regionCode,items(kind,id,snippet(channelId,title,description,channelTitle))"
)
response = request.execute()

We can use region code to filter an API request’s response based on any region. It can be used with different resources and methods supported by the API.