Alaouy\Youtube\Youtube::getPopularVideos PHP Méthode

getPopularVideos() public méthode

Gets popular videos for a specific region (ISO 3166-1 alpha-2)
public getPopularVideos ( $regionCode, integer $maxResults = 10, $part = ['id', 'snippet', 'contentDetails', 'player', 'statistics', 'status'] ) : array
$regionCode
$maxResults integer
Résultat array
    public function getPopularVideos($regionCode, $maxResults = 10, $part = ['id', 'snippet', 'contentDetails', 'player', 'statistics', 'status'])
    {
        $API_URL = $this->getApi('videos.list');
        $params = array('chart' => 'mostPopular', 'part' => implode(', ', $part), 'regionCode' => $regionCode, 'maxResults' => $maxResults);
        $apiData = $this->api_get($API_URL, $params);
        return $this->decodeList($apiData);
    }

Usage Example

 public function testGetPopularVideos()
 {
     $maxResult = rand(10, 40);
     $regionCode = 'us';
     $response = $this->youtube->getPopularVideos($regionCode, $maxResult);
     $this->assertNotNull('response');
     $this->assertEquals($maxResult, count($response));
     $this->assertEquals('youtube#video', $response[0]->kind);
     $this->assertObjectHasAttribute('statistics', $response[0]);
     $this->assertObjectHasAttribute('status', $response[0]);
     $this->assertObjectHasAttribute('snippet', $response[0]);
     $this->assertObjectHasAttribute('contentDetails', $response[0]);
 }