0

I try using the chart parameter to get trending videos, 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'

Please Help
  • 929
  • 1
  • 8
  • 11
  • I think chart is a filter not a parameter. However, I do not know the syntax for filter, chart=mostPopular in place of id did not work. – Please Help Apr 20 '17 at 21:59
  • jesus stack overflow is so unhelpful I have never gotten any youtube api support what is this – Please Help Apr 20 '17 at 22:34

1 Answers1

1

You are looking for Videos list endpoint not Search list endpoint, you can get the most popular videos for your regionCode & videoCategoryId with :

$videosResponse = $youtube->videos->listVideos('snippet', array(
    'chart' => 'mostPopular',
    'maxResults' => 50,
    'regionCode' => 'GB',
    'videoCategoryId' => '23'
));
Bertrand Martel
  • 42,756
  • 16
  • 135
  • 159
  • You, Good Sir, are a god <3 – Please Help Apr 21 '17 at 20:00
  • This sample calls the API's search.list method with the type, q, location and locationRadius parameters to retrieve search results matching the provided keyword within the radius centered at a particular location. Using the video IDs from the search result, the sample calls the API's videos.list method to retrieve location details of each video. – Please Help Apr 21 '17 at 20:03
  • That's what it says in the videos list reference – Please Help Apr 21 '17 at 20:03
  • I didn't find direct example for most popular videos in PHP, I just looked at the fields for [video list](https://developers.google.com/youtube/v3/docs/videos/list) and transposed this with the sample you have referenced in your comment – Bertrand Martel Apr 21 '17 at 20:20