Souvik Maity
Souvik Maity

Reputation: 127

Youtube API v3 data.search returning same value

I was trying to fetch different youtube channels on the basis of the regionCode.

Trying to fetch indian youtube channels:

https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&regionCode=IN&maxResults=5&key={API_KEY}

Trying to fetch Malaysian youtube channels:

https://www.googleapis.com/youtube/v3/search?part=snippet&type=channel&regionCode=MY&maxResults=5&key={API_KEY}

I am getting same result for both of this requests. Why this is happening?

{
 "kind": "youtube#searchListResponse",
 "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/EiqwT6pG1EkwVEl17s1_qudvkmk\"",
 "nextPageToken": "CAUQAA",
 "pageInfo": {
  "totalResults": 1000000,
  "resultsPerPage": 5
 },
 "items": [
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/smpwgLdS9Og11NhpzRYcy37a9V8\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCrFiA0hztL9e8zTi_qBuW4w"
   },
   "snippet": {
    "publishedAt": "2013-03-19T20:35:41.000Z",
    "channelId": "UCrFiA0hztL9e8zTi_qBuW4w",
    "title": "EeOneGuy",
    "description": "Просто делаю ролики =)",
    "thumbnails": {
     "default": {
      "url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
     },
     "medium": {
      "url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
     },
     "high": {
      "url": "https://lh6.googleusercontent.com/-ZPtgaY_lFDY/AAAAAAAAAAI/AAAAAAAAAAA/U_8gJcnIMiE/photo.jpg"
     }
    },
    "channelTitle": "EeOneGuy",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/g4m9Kno2zbU7BMIEUbffxDlyvZI\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UC7MO7ngSqsBcvQvxNf-kpWg"
   },
   "snippet": {
    "publishedAt": "2013-06-04T17:39:49.000Z",
    "channelId": "UC7MO7ngSqsBcvQvxNf-kpWg",
    "title": "The Right to Research Coalition",
    "description": "The Right to Research Coalition is a coalition of 80 undergraduate and graduate student organisations from across the world. Together we educate and ...",
    "thumbnails": {
     "default": {
      "url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
     },
     "medium": {
      "url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
     },
     "high": {
      "url": "https://lh5.googleusercontent.com/-p0RT2XiO3_0/AAAAAAAAAAI/AAAAAAAAAAA/tdAJTswPnB0/photo.jpg"
     }
    },
    "channelTitle": "R2RCvideo",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/nWC7qhbPZRH0qyEBOcWdFR8TI5k\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCmSSq5573Ru9asXsXykgqTw"
   },
   "snippet": {
    "publishedAt": "2014-10-12T02:26:56.000Z",
    "channelId": "UCmSSq5573Ru9asXsXykgqTw",
    "title": "Toys Games TV",
    "description": "Welcome to Toys Games TV Channel! Looking for a safe channel for your kids? Look no further, on TGTV we review primarily Disney, PBS & Sprout character ...",
    "thumbnails": {
     "default": {
      "url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
     },
     "medium": {
      "url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
     },
     "high": {
      "url": "https://lh3.googleusercontent.com/-5qqjMUWhRow/AAAAAAAAAAI/AAAAAAAAAAA/2la9IA5DNhU/photo.jpg"
     }
    },
    "channelTitle": "ToysGamesTV",
    "liveBroadcastContent": "upcoming"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/enqEI6qDr8UfYcjixI9Cjpd6SU0\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCtjLPHCyI5V-xuumAXzAizA"
   },
   "snippet": {
    "publishedAt": "2008-06-05T04:13:13.000Z",
    "channelId": "UCtjLPHCyI5V-xuumAXzAizA",
    "title": "UNUChannel",
    "description": "Channel produced by the United Nations University (UNU). The overarching goal of the United Nations University is to contribute to global sustainable ...",
    "thumbnails": {
     "default": {
      "url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/1.jpg"
     },
     "medium": {
      "url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/mq1.jpg"
     },
     "high": {
      "url": "https://i.ytimg.com/i/tjLPHCyI5V-xuumAXzAizA/hq1.jpg"
     }
    },
    "channelTitle": "UNUChannel",
    "liveBroadcastContent": "none"
   }
  },
  {
   "kind": "youtube#searchResult",
   "etag": "\"iDqJ1j7zKs4x3o3ZsFlBOwgWAHU/44t2atyjsxpSOVj7OfeK9GTfy0M\"",
   "id": {
    "kind": "youtube#channel",
    "channelId": "UCJ7-0_cR9HiA9iX8n3kugcg"
   },
   "snippet": {
    "publishedAt": "2010-06-29T15:08:02.000Z",
    "channelId": "UCJ7-0_cR9HiA9iX8n3kugcg",
    "title": "Naturhistoriska riksmuseet",
    "description": "Naturhistoriska riksmuseets och Cosmonovas YouTube-kanal.",
    "thumbnails": {
     "default": {
      "url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
     },
     "medium": {
      "url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
     },
     "high": {
      "url": "https://lh5.googleusercontent.com/-OItSjQXSj_c/AAAAAAAAAAI/AAAAAAAAAAA/ybdmiik-0eA/photo.jpg"
     }
    },
    "channelTitle": "SthlmNaturhistoriska",
    "liveBroadcastContent": "none"
   }
  }
 ]
}

Thanks in advance. Any help would be much appreciated.

Upvotes: 0

Views: 424

Answers (1)

not_a_bot
not_a_bot

Reputation: 2362

From the documentation:

regionCode - (string) The regionCode parameter instructs the API to return search results for the specified country. The parameter value is an ISO 3166-1 alpha-2 country code.

It looks like specifying the regionCode returns search results as if you were in that country, not for videos/channels that are associated with that country. For example, if you specified CN (China) as the region code, you wouldn't get results for videos that have been blocked in China.

It seems that there's no good way to get all channels that belong to a particular country. What you could do is execute the search.list() with your specified search criteria and set type=Channel. Then, based on the response, issue a request to channels.list() to get the country and compare to see if it is from that specific country. It's pretty inefficient, and while I was trying to test a similar way of doing it, I found that I can set my country in the "About" section of my channel. However, since the field is optional, there's no guarantee that users are actually setting this for their channels, so ultimately it's hard for you to get the information you're looking for.

Upvotes: 1

Related Questions