It’s a well-known fact that Google provides a big number of electronic products and services that can be used from the simplest end-user, to the most sophisticated one. But further than those who just use the Google services as they’re provided, there are people who need to have a different kind of access to them; developers. Indeed, Google gives great assistance to developers of all kind to create multi-platform applications that use their services, as it provides various Application Protocol Interfaces (APIs) that can be used in many ways, as well as already-made libraries and SDKs for various programming languages.
As the Google APIs and services can be utilized in mobile platforms as well, apparently we could not just be left uninterested here, and as a matter of fact, we’ve already dealt with Google technologies in the past. For example, here’s a tutorial about the Google Maps SDK. Now, in this tutorial, we’re going to see for first time a totally different service, the YouTube API.
Working with that specific API is fairly easy, but there are a few certain aspects you should already know about, otherwise your life could become a bit difficult. Let me give you some clues: First of all, we won’t use any SDK, or iOS-specific library. Instead, we’ll make simple HTTP requests (GET requests actually) to fetch data from Google. The results are in JSON format, so it’s required you already know how data is formed in JSON. You don’t have to be a JSON expert; just to understand the format. If you need assistance, here you can find some valuable information.
The Google documentation regarding the YouTube API is really big, so my intention here is to gather information from various pages into one place and help you get started with this API fast and easily. Even though we are about to cover just a small portion of the YouTube API, what you will learn will show you the way for the rest of it. However, I have to mandatorily mention a few facts before we continue.
As I mentioned above, we are going to make HTTP requests to the YouTube API for getting data back. Those requests trigger specific methods to be performed, and they actually represent a specific task of the API. For example, the channels.list method refers to the request needed to be made so data for one or more channels can be retrieved. Of course, I will provide you with the respective documentation link for every method (HTTP request) we are about to meet next. Each method accepts some parameters and filters. In the parts that we’ll make use of such methods I’ll let you know what parameters and filters we are about to use (and why), but for details about them you have to go and read more information in the provided links. It would be totally pointless to copy here the Google documentation.
From all the requests that can be made to the API, some of them require user authorization and some not. For the first case, the OAuth 2.0 protocol must be used so a user can securely sign in with a Google account. For the second, a simple API key is just enough to allow unauthorized requests. In this tutorial though we will deal with the second case only, and we won’t ask from users to sign in. Trust me, it takes more than one tutorial to cover all these topics in one place.
I strongly advice you to read this tutorial and some specific parts of the Google documentation side by side. If you want to get a first taste, the following links may help you:
- YouTube Data API Reference
- YouTube Data API Overview
- Implementation and Migration Guide
- Searching for Content
Besides the above, feel free to navigate around and read everything you find interesting. Just for the record, we are going to use the YouTube API v3, as this is what Google suggests nowadays. As a final note, it has been unavoidable to give you all those links (not only the links above, but those that are about to come too), as the Google documentation is too extended. It’s been also necessary so I manage to keep the scope of this tutorial in reasonable limits.
So, let’s get going, and by the end of this tutorial you will have an application that will be able to download channels and videos, make searches, and playback videos. The details are coming.