Search code examples
phpyoutube-apiyoutube-data-apitrending

How to get trending videos using youtube API v3 and PHP


I tried using the chart parameter with the YouTube API, but it says that chart is not a valid parameter. I am using PHP. I have the region and category and everything set fine. Is this a bug? How do I do it?

Here is the code I have

  $searchResponse = $youtube->search->listSearch('id,snippet', array(
        //'type' => 'video',
        'part' => 'snippet',
          'location' => 'GB',
          'videoCategoryId' => '23',
         'chart' => 'mostPopular',
        'order' => 'date',
        'maxResults' => '50'
    ));

Says:

An client error occurred: (list) unknown parameter: 'chart'


Solution

  • like so:

    $trendingComedy = $youtube->videos->listVideos('snippet', array(
        'chart' => 'mostPopular',
        'maxResults' => 50,
        'regionCode' => 'GB',
        'videoCategoryId' => '23'
    ));
    

    use listVideos not listSearch