Are you in the process of developing an application designed to incorporate one or more of the Google APIs? Do you already have an application and want to add Google data to it? Are you having problems understating where to start? I am going to try to give you some tips on where and how to get started.
This article is going to be very short but it is going to spawn
Google has an extensive list of APIs that they have released for public use. Most of the APIs are free Google does not charge us to access the APIs. However there are a few of the Google APIs that you do have to pay to access or pay to access more then the default number of requests. You should always check into the quota of the API to find out how many request you are allowed to make before you may have to start paying for the privilege of using the API. Google will not charge you unless you accept the billing terms so don’t worry you aren’t going to suddenly start getting a bill from google if you go over the number of request.
You can find a list of all of the APIs here. Google APIs Explorer
What is quota?
Quota is how many requests you are allowed to make to a Google API without requesting permission to access more. Most of the Google APIs have a free quota, a number of requests Google lets you make without asking for permission to make more request. It does not always cost you anything to extend your quota it depends upon the API if you are going to have to pay for permission to make additional requests
Unless it says, otherwise APIs Quotas are projects based not user based.
Each API has different quotas I encourage you to check the API you are using for information about the quota it has available the following examples are from the YouTube API.
Project quota example
If I authenticate the application and make 10,000,000 requests, then you authenticate the application and make 40,000,000 requests the quota limit will have been reached and any additional request will result in the following error.
dailyLimitExceeded A daily quota limit for the API has been reached.
You will have to wait until midnight Pacific Standard Time(PST) before you can make more requests.
Google project Quotas reset at midnight Pacific Standard Time(PST) this is the west coast USA timezone.
Personally I think it would have been more logical to reset it at GMT time but Google is located in the PST time zone so maybe it’s easier for them to understand.
User quota example
Per-user limit 3,000 requests/second/user
Some Quotas are user based, a user is normally the person that has authenticate the request so it is hard to understand how it comes into play with a public API key but it does. Every request sent to google contains information about who is making the request in the form of the IP address where the address came from. If you have, your code running on a server the IP address is the same all the time so google sees it as the same user. You can get around his by adding Quotauser to your request this will identify the request based upon different users.
If you send to many requests to fast from the same user you will see the following error.
userRateLimitExceeded The request failed because a per-user rate limit has been reached.
The best way to get around this is to use QuotaUser in all of your requests, and identify different users to Google.
For example: The YouTube API allows you to get a list of all videos without authentication but to insert a video you must be authenticated. That is because list videos gets a list can get a list of public videos while inserting must be into a user’s account you need the permission of the user to upload a video to their account.
So there are two types of data we can access with the Google APIs they are public and private. Private data is data that is owned by a user, my GMail account is private my files on Google drive are also private, if you want to access them you have to have my permission to get my permission I must authenticate your application and grant you permission.
Public data is data that is accessible by anyone, if I upload a video to YouTube and set it to public anyone can see it without being logged into Google .
You should check the documentation for the method you are using to find out if it requires authentication or not. If you see the following, you will know that you need to be authenticated to access this information.
This request requires authorization with at least one of the following scopes.
What are scopes?
I will be talking about scopes more in the Oauth2 section of this blog series. Scopes are a way of telling the user, what access you need. When you request access from the user you can tell them I need to be able to write to your YouTube account, or I just need to view your YouTube account.
Creating a project
In order to use Googles APIs you must first register your project on Google Developer console. This is so that Google can keep track of the Quota of how much you are using it. It also helps them to prevent attacks if they know who is making the request they can shut down the account before it causes any problems with their servers. We will be looking at how to do this in the next five articles.
Google has created a number of client libraries for accessing their APIs to my knowledge they are all open source projects so you are welcome to help. If you can, I encourage you to use the client libraries I have used a number of them and find that they save me a lot of time. You can find a list of the Google client libraries here.
All of the requests to Googles APIs are simple HTTP POSTS or HTTP GETs so you do not need to use a client library if you are willing to code it from the ground up yourself.
Google has a large number of APIs that they let us use to access data on their servers. We must create a project on Google developer console before we can begin accessing data on Google servers. Google has created a number of client libraries that make it easier for us to access data though the Google APIs.
Join me for the next post in this series how to create a project on Google Developer console.