diff --git a/src/Youtube.php b/src/Youtube.php index 612fdb8..fa6c7f9 100644 --- a/src/Youtube.php +++ b/src/Youtube.php @@ -338,6 +338,24 @@ public function getChannelById($id, $optionalParams = false) return $this->decodeSingle($apiData); } + /** + * @param array $ids + * @return \StdClass + * @throws \Exception + */ + public function getChannelsById($ids = array(), $optionalParams = false) + { + $API_URL = $this->getApi('channels.list'); + $params = array( + 'id' => implode(',', $ids), + 'part' => 'id,snippet,contentDetails,statistics,invideoPromotion' + ); + if($optionalParams){ + $params = array_merge($params, $optionalParams); + } + $apiData = $this->api_get($API_URL, $params); + return $this->decodeList($apiData); + } /** * @param $channelId diff --git a/tests/YoutubeTest.php b/tests/YoutubeTest.php index 27eb103..7c3d8a4 100644 --- a/tests/YoutubeTest.php +++ b/tests/YoutubeTest.php @@ -225,6 +225,19 @@ public function testGetChannelById() $this->assertObjectHasAttribute('statistics', $response); } + public function testGetChannelsById() + { + $channels = array('UCk1SpWNzOs4MYmr0uICEntg', 'UCK8sQmJBp8GCxrOtXWBpyEA'); + $response = $this->youtube->getChannelsById($channels, $this->optionParams); + + $this->assertTrue(count($response) === 2); + $this->assertEquals('youtube#channel', $response[0]->kind); + $this->assertObjectHasAttribute('snippet', $response[0]); + $this->assertObjectHasAttribute('contentDetails', $response[0]); + $this->assertObjectHasAttribute('statistics', $response[0]); + } + + public function testGetPlaylistsByChannelId() { $GOOGLE_CHANNELID = 'UCK8sQmJBp8GCxrOtXWBpyEA';