youtube类视频限制不起作用

时间:2017-09-01 18:14:52

标签: php youtube youtube-api youtube-data-api

我想更改主页上的视频限制(getpopularvideos),但是当我更改限制时,它始终只显示20个视频。

我做错了什么?

protected function getPopularVideos($limit = NULL){
    // Set Limit
    if(!is_null($limit)) $this->limit = $limit; 
    // Construct URL
    $part = "snippet,contentDetails,statistics";
    $this->url = "https://www.googleapis.com/youtube/v3/videos?key={$this->key}&part=$part&chart=mostPopular&maxResults={$this->limit}";
    if(!is_null($this->page)) $this->url = $this->url."&pageToken={$this->page}";
    // Get Data
    $data = Main::cache_get("popular_{$this->page}");
    if($data == NULL){
        $data = $this->http(TRUE);          
        Main::cache_set("popular_{$this->page}", $data); $limit = 24;
    }
    $i = 1;
    $html = "<ul class='media'>";
    foreach ($data->items as $yt) {
        $html .= $this->listVideo($yt);

        if($i%24 == 0) {
            $html .= "</ul>{$this->ads(728)}<ul class='media'>";
        }

        $i ++;
    }
    $html .= "</ul>";
    $this->pagination = "<ul class='list-inline'>";
        if(isset($data->prevPageToken)){
            $this->pagination .= "<li  ><a href='{$this->config["url"]}/popular/{$data->prevPageToken}' class='btn btn-ghost'><i class='btn-icon btn-icon--left ninety9lives-youtube-play'></i> Previous</a></li>";
        }
        if(isset($data->nextPageToken)){
            $this->pagination .= "<li  ><a href='{$this->config["url"]}/popular/{$data->nextPageToken}' class='btn btn-ghost'><i class='btn-icon btn-icon--left ninety9lives-youtube-play'></i> Next</a></li>";
        }           
    $this->pagination .= "</ul>";
    return $html;
}

protected function getUserVideos4Home($q, $limit = NULL){
    if(!is_null($limit)) $this->limit = $limit;

    $part = "snippet";      

    $this->url = "https://www.googleapis.com/youtube/v3/search?key={$this->key}&part=$part&order=date&type=video&channelId={$q}&maxResults={$this->limit}"; 
    if(!is_null($this->page)) $this->url = $this->url."&pageToken={$this->page}";
            $data = $this->http(TRUE);      
    $i = 1;
    $return = new stdClass();
    $return->title = $data->items[0]->snippet->channelTitle;

    $html .= "";
    $vids = array();

    foreach ($data->items as $yt){
        $vids[] = $yt->id->videoId; 
    }
    $videos2 = implode(",", $vids);

    $part = "snippet,contentDetails,statistics";

    $this->url = "https://www.googleapis.com/youtube/v3/videos?key={$this->key}&part={$part}&id={$videos2}";

    $data2 = $this->http(TRUE);

    $durations = Main::durations($vids);

    foreach ($data->items as $yt) {
        $html .= $this->listSearchVideo12($yt,$durations[$yt->id->videoId]);

        if($i%6 == 0) {
            $html .= "</div><div class='adblock'><div class='img'>Google AdSense<br>336 x 280</div></div><div class='list'>";
        }

        $i ++;
    }
    $html .= "";



    return $html;       
}

0 个答案:

没有答案