在youtube API php中获得错误的结果数量

时间:2017-06-29 07:48:31

标签: php youtube

我正在尝试使用以下代码从youtube上获取视频:

        $youtube_api_url = "https://www.googleapis.com/youtube/v3/search?key=".$new_key->api_key;
        $youtube_api_url = $youtube_api_url."&order=relevance&type=video&maxResults=20&part=snippet&videoCategoryId=10&q=". urlencode(preg_replace('/[^a-zA-Z0-9_ %\[\]\.\(\)%&-]/s', '',$trackRecord->name));
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_URL,$youtube_api_url);
        $result=curl_exec($ch);

        $response = json_decode($result, true);
        echo "<pre>"; print_r($response); die;

返回错误的结果数量如下:

Array
( 
    [items] => Array
        (
            [0] => Array
                (
                    [kind] => youtube#searchResult
                    [etag] => "m2yskBQFythfE4irbTIeOgYYfBU/ne5AZXpdoLtAn-mlwu4ipioOQ_I"
                    [id] => Array
                        (
                            [kind] => youtube#video
                            [videoId] => dB0ITzfbwfw
                        )

                    [snippet] => Array
                        (
                            [publishedAt] => 2017-01-23T17:31:23.000Z
                            [channelId] => UCdW5nPo1oyD2vLkvoYijmEg
                            [title] => Lihtz Kamraz "The Switch Up" Interview Part 2
                            [description] => In 2016, a lot of break out artists emerged and made a mark in the game. As 2017 begins, one name that you should definitely be on the lookout for is Lihtz ...
                            [thumbnails] => Array
                                (
                                    [default] => Array
                                        (
                                            [url] => https://i.ytimg.com/vi/dB0ITzfbwfw/default.jpg
                                            [width] => 120
                                            [height] => 90
                                        )

                                    [medium] => Array
                                        (
                                            [url] => https://i.ytimg.com/vi/dB0ITzfbwfw/mqdefault.jpg
                                            [width] => 320
                                            [height] => 180
                                        )

                                    [high] => Array
                                        (
                                            [url] => https://i.ytimg.com/vi/dB0ITzfbwfw/hqdefault.jpg
                                            [width] => 480
                                            [height] => 360
                                        )

                                )

                            [channelTitle] => HIPHOPSINCE1987TV
                            [liveBroadcastContent] => none
                        )

                )

        )

)

正如您所看到的那样,它显示了总页数和每页结果:

[pageInfo] =&gt;排列         (             [totalResults] =&gt; 14             [resultsPerPage] =&gt; 20         )

如何获得所有结果?

0 个答案:

没有答案