0

Hello I'm am now on a project that using YouTube api, I am bit of stuck on how to fetch top 10 channel of a content owner at YouTube by using their api. Right now what i am doing is that i need to loop all the channel i had and sort it by their views.

loop {

$analytics = $youtube->reports->query('contentOwner==$content_id', $start_date , $end_date , 'views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration,shares,estimatedRevenue,estimatedAdRevenue,monetizedPlaybacks,adImpressions',array('filters'=> $id ,'max-results'=>$max_result));

}

It is fine but as it need to loop all the channel it takes quite some time. Is there any other way to fetch top 10 channel directly ?

By the way, is there any other way to by pass user consent?

  • You taged this Youtube api but the call you are using is for YouTube Analayitcs API which api are you using exactly? Can you clean up your question / code. – Linda Lawton - DaImTo Jun 25 '18 at 06:17
  • there are 3 youtube api , which is analytics, data, and reporting . i used data in order to get the channel list, but to get the views etc i used youtube analytics api. i just tagged it to youtube api. – ikhwan salihin Jun 25 '18 at 06:49
  • The code you have included $youtube->reports->query is reporting api is your question about reporting api if so please fix your tags. if not change your code to reflect the api the question is about. – Linda Lawton - DaImTo Jun 25 '18 at 07:06

1 Answers1

-1

problem solved after i do a lot of try and error, youtube provide an api explorer for developer to test query parameter right away.

youtube api explorer

as i explain in the question i had successfully able to fetch/retrieve the data for a channel by using loop.

actually i can just put every channel id with comma to retrieve all the channel i manage.

before PHP example

 loop {


    $id = 'channel==' . $id;

        $analytics = $youtube->reports->query('contentOwner==$content_id', $start_date , $end_date , 'views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration,shares,estimatedRevenue,estimatedAdRevenue,monetizedPlaybacks,adImpressions',array('filters'=> $id ,'max-results'=>$max_result));

}

new or solved php example

$id = 'channel==' . implode(',', $id);
$analytics = $youtube->reports->query('contentOwner==$content_id', $start_date , $end_date,'views,comments,likes,dislikes,estimatedMinutesWatched,averageViewDuration,shares,estimatedRevenue,estimatedAdRevenue,monetizedPlaybacks,adImpressions',array('filters'=> $id ,'max-results'=>$max_result));

youtube already give the documentation on how to use their api, but i think it is quite hard to understand. Therefore i am able to use the api only when i do alot of try and error.

Thank you.