The Google Cloud Developer Challenge is on right now with just about a month left and I thought it would be good to try out building something simple but entertaining within a short period on it. And release the source code for anyone to see the ease and hopefully inspire more interesting ideas.
The idea I choose
One simple idea came to mind. A site showcasing the funniest "homegrown" YouTube videos from Nigeria.
A better definition is 'Find & Watch the funny videos in Nigeria watched by your friends'.
Below is a screenshot
The name I chose
Why? Just because 🙂
Showcasing the videos is the easiest part. It's just a database of a list of videos. I can sort it anyway I like. Allowing people to submit YouTube videos is just as easy.
On the other hand, finding the ones watched by your friends is 'trickier'. Google+ Sign In came to the rescue for that. More on this later in this post.
The how I chose
Thankfully, my everyday language – PHP is now supported on the Google App Engine, hence it was quite easy to get started on the project.
Google App Engine supports four languages – Java, Python, Go and PHP. If you haven't checked out Google App Engine lately or you are just hearing about Google App Engine, then the following page is for you – https://developers.google.com/appengine/docs/whatisgoogleappengine.
BTW – there are lots of interesting projects you can build on GAE like Realtime Multiplayer games using the Python or Java.
So my plan was to use PHP + MySQL + YouTube Content + YouTube API + Google+ API.
- First I registered on https://gaeforphp.appspot.com/. (Now your PHP apps get approved immediately)
- I downloaded the Google App Engine SDK
- I created a Database Instance [https://developers.google.com/cloud-sql/docs/instances#creating ] and created my database.
- BTW – Google Cloud SQL is not free, but you can sign up like I did for the FREE Starter Pack which comes with 2000 USD worth of credit. [https://cloud.google.com/resources/starterpack/]
- On my local system, I created the same database and created my tables.
- I created a very simple table structure for the videos. Every video on YouTube has a unique identifier, so I'm storing that, as well as the title and description of the video.
- Lastly, I'm storing the number of views of the video.
Below is a screenshot of the database structure –
In total, I have 4 tables –
- Users – holds users registered
- Vvideos – holds the video information, how many views in total
- Friends – holds the list of friends attached to each user. Friends form G+ circles
- Views – holds which video has been seen by which user.
I'm a console-first person so I used the google-sql command line. However, Google provides a page just for importing data and running sql statements for your database instance – https://developers.google.com/cloud-sql/docs/sql_prompt
Next Step – I looked at the YouTube API [https://developers.google.com/youtube/v3/] , to find out which one would allow me to pull the information about any YouTube video.
By sending the YouTube ID, I could now get the name, length, description etc of the video. So I save those.
The Look I Chose
I love simple. I hate having to create a look and feel from scratch. I avoid it actually. Hence I used and still use Twitter Bootstrap. A LOT. So I just picked used that.
Google provides a lot of code – called Client Libraries for plenty of its APIs. These client libraries are available for different languages [https://developers.google.com/youtube/v3/libraries]. So I downloaded the one for PHP. And used the code below to pull the YouTube info and the response received from the call.
Those were the easy parts.
The harder part was solved using G+ sign-in. Seeing what videos your friends have watched involves a series of steps –
- You must be signed-in.
- You need to grant access to your Google+ Circles.
- FunnyLeni must compare your circle of friends with the list of users registered on FunnyLeni.
- If any of your friends match, then great!
Moreover, anyone can submit a video from YouTube.
I could have used frameworks like CakePHP or FuelPHP or CodeIgniter etc, but I thought it would be easier for anyone to follow if I did not use those. So I built a micro-mini controller (FunnyLeni::handleRequest) to handle the VC part of MVC.
Finally you can check it out on http://funnyleni.appspot.com.
The entire code for the first release is available on github here – http://goo.gl/8VRQY6. Warning – I wrote this in a hurry (less than 12 hours) so naturally there's room for improvement and refactoring. There are probably things I could have done much better if I took more time to think. Feel free to poke holes, suggest features and let me know on the mailing list.
I've also learnt that writing code is easier than writing a blog post about it this way. It's taken me longer than 12 hours to write this post.
The Google Cloud Developer Challenge is still on. Check out this comprehensive video on getting started with Google App Engine – https://www.youtube.com/watch?v=8jRabiFLvZQ or another cool but short one for PHP – https://www.youtube.com/watch?v=cj09WbpZ32w
If you are looking for Ideas for Great Apps and Real life use cases of App Engine – this video is a great place to start. https://www.youtube.com/watch?v=uiw2XUGa3U8.
Follow the #gcdc hashtag as well.