Algorithm for videos

I need to figure out, how to make a trending videos type thing. Where the most viewed will put it at the top of the list. I know youtube has an API system for this… If I can get the correct code for this and how to do it would be even better.

Thank You.

@Waldo Just tagging you in this post.