Skip to content

Commit 6494855

Browse files
authored
Merge pull request #55 from JavierMartinz/patch-1
Add getChannelsById
2 parents 4df5de3 + 45f7f83 commit 6494855

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

src/Youtube.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,24 @@ public function getChannelById($id, $optionalParams = false)
338338
return $this->decodeSingle($apiData);
339339
}
340340

341+
/**
342+
* @param array $ids
343+
* @return \StdClass
344+
* @throws \Exception
345+
*/
346+
public function getChannelsById($ids = array(), $optionalParams = false)
347+
{
348+
$API_URL = $this->getApi('channels.list');
349+
$params = array(
350+
'id' => implode(',', $ids),
351+
'part' => 'id,snippet,contentDetails,statistics,invideoPromotion'
352+
);
353+
if($optionalParams){
354+
$params = array_merge($params, $optionalParams);
355+
}
356+
$apiData = $this->api_get($API_URL, $params);
357+
return $this->decodeList($apiData);
358+
}
341359

342360
/**
343361
* @param $channelId

tests/YoutubeTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ public function testGetChannelById()
225225
$this->assertObjectHasAttribute('statistics', $response);
226226
}
227227

228+
public function testGetChannelsById()
229+
{
230+
$channels = array('UCk1SpWNzOs4MYmr0uICEntg', 'UCK8sQmJBp8GCxrOtXWBpyEA');
231+
$response = $this->youtube->getChannelsById($channels, $this->optionParams);
232+
233+
$this->assertTrue(count($response) === 2);
234+
$this->assertEquals('youtube#channel', $response[0]->kind);
235+
$this->assertObjectHasAttribute('snippet', $response[0]);
236+
$this->assertObjectHasAttribute('contentDetails', $response[0]);
237+
$this->assertObjectHasAttribute('statistics', $response[0]);
238+
}
239+
240+
228241
public function testGetPlaylistsByChannelId()
229242
{
230243
$GOOGLE_CHANNELID = 'UCK8sQmJBp8GCxrOtXWBpyEA';

0 commit comments

Comments
 (0)