library/Oembed/YouTube.php
public function getPlaylist() : array
    {
        if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) {
            return array();
        }

        $theEnd = false;
        $nextPageToken = true;

        $items = array();

        while ($nextPageToken) {
            $endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY;

            if (is_string($nextPageToken) && !empty($nextPageToken)) {
                $endpointUrl .= '&pageToken=' . $nextPageToken;
            }

            $response = wp_remote_get($endpointUrl);

            // If response code is bad return
            if (wp_remote_retrieve_response_code($response) !== 200) {
                return array();
            }

            $result = json_decode(wp_remote_retrieve_body($response));
            $items = array_merge($items, $result->items);

            $nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false;
        }

        return $items;
    }
public function getPlaylist() : array
    {
        if (!defined('MUNICIPIO_GOOGLEAPIS_KEY') || !MUNICIPIO_GOOGLEAPIS_KEY || !isset($this->params['list'])) {
            return array();
        }

        $theEnd = false;
        $nextPageToken = true;

        $items = array();

        while ($nextPageToken) {
            $endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $this->params['list'] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY;

            if (is_string($nextPageToken) && !empty($nextPageToken)) {
                $endpointUrl .= '&pageToken=' . $nextPageToken;
            }

            $response = wp_remote_get($endpointUrl);

            // If response code is bad return
            if (wp_remote_retrieve_response_code($response) !== 200) {
                return array();
            }

            $result = json_decode(wp_remote_retrieve_body($response));
            $items = array_merge($items, $result->items);

            $nextPageToken = isset($result->nextPageToken) ? $result->nextPageToken : false;
        }

        return $items;
    }
public function getPlaylist ( ) : array { if ( ! defined ( 'MUNICIPIO_GOOGLEAPIS_KEY' ) || ! MUNICIPIO_GOOGLEAPIS_KEY || ! isset ( $ this -> params [ 'list' ] ) ) { return array ( ) ; } $ theEnd = false ; $ nextPageToken = true ; $ items = array ( ) ; while ( $ nextPageToken ) { $ endpointUrl = 'https://www.googleapis.com/youtube/v3/playlistItems?playlistId=' . $ this -> params [ 'list' ] . '&part=snippet&maxResults=50&key=' . MUNICIPIO_GOOGLEAPIS_KEY ; if ( is_string ( $ nextPageToken ) && ! empty ( $ nextPageToken ) ) { $ endpointUrl .= '&pageToken=' . $ nextPageToken ; } $ response = wp_remote_get ( $ endpointUrl ) ; // If response code is bad return if ( wp_remote_retrieve_response_code ( $ response ) !== 200 ) { return array ( ) ; } $ result = json_decode ( wp_remote_retrieve_body ( $ response ) ) ; $ items = array_merge ( $ items , $ result -> items ) ; $ nextPageToken = isset ( $ result -> nextPageToken ) ? $ result -> nextPageToken : false ; } return $ items ; }
Get playlist items
@return array Playlist
Get playlist items