Google Development for beginners 11


Please Share

googleDevAre 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 four five more posts that will continue to walk you though becoming a Google Developer.

Google APIs

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

50,000,000 units/day

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.

Authentication

Depending upon which Google API you are interested in you may need to be authenticated to access the data.   In some cases, the different methods within an API may have different authentication requirements.

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.

Client Libraries

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.

Conclusion

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.

Please Share


Linda Lawton

About Linda Lawton

My name is Linda Lawton I have more than 20 years experience working as an application developer and a database expert. I have also been working with Google APIs since 2012 and I have been contributing to the Google .Net client library since 2013. In 2013 I became a a Google Developer Experts for Google Analytics.


Leave a comment

Your email address will not be published. Required fields are marked *

11 thoughts on “Google Development for beginners

  • Bill Beale

    Hi Linda, Do you provided paid consulting advice? I’m a software developer and have a module in my application that uses the geocode API. It is currently working well but with the key provided by the programmer. I’ve been going round in circles through Google web sites and Stackoverflow trying to, firstly, open a Google Developers account to get a developer’s key for myself to extend the use of the geocoding API in a PowerBuilder client server application and, thereafter, to set up user accounts for the API for clients who use my application. Your site is very informative but I can’t find a way to get to even first base and open a developer’s account. If you do not consult, can you refer me to someone who could assist?

  • Renuka

    Hi,

    I am trying to insert mail having attachment of size more than 5 mb using Google API.
    It is throwing exception : An Error occurred, but the error response could not be deserialized.

    I have raised same question on http://stackoverflow.com/questions/38434260/exception-while-inserting-mail-having-attachment-as-a-pdf-of-size-more-than-5mb

    http://stackoverflow.com/questions/38450127/c-sharp-upload-attachment-using-google-apis-gmail-v1-usersresource-messagesresou

    Please suggest solution.

    Thank you.

  • Renuka

    I tried this:
    string f_readLines = System.IO.File.ReadAllText(@p_EMLPath);
    f_bytes = System.Text.Encoding.UTF8.GetBytes(f_readLines);
    f_MsgRawStr = Convert.ToBase64String(f_bytes).Replace(‘+’, ‘-‘).Replace(‘/’, ‘_’).Replace(“=”, “”);
    Message f_message = new Message();
    f_message.Raw = f_MsgRawStr;
    f_message.LabelIds = “INBOX”;
    Google.Apis.Gmail.v1.UsersResource.MessagesResource.InsertRequest f_ReqforMail = m_MailService.Users.Messages.Insert(f_message, “me”);
    f_ReqforMail.Execute();

    Still same exception.
    Please suggest solution to insert mail having attachments of size more than 5mb.

  • G

    Hi Linda

    I’m experimenting for the first time with the Google Sheets API (v4) in C#
    I’ve been through the quick start sample, and set values in a Google sheet. I’ve now moved on to trying to update cell formats.
    I’ve had some success, but it’s not complete! I am fairly confused by the ‘fields’ field (or FieldMask) of the UpdateCellsRequest.
    I am trying to change the background colour of a range of cells. If I specify “*”, the update (always) seems to work, but wipes out the cell value in the process. If I specify “UserEnteredValue(BackgroundColor)” it seems to work once when I first run my program. If I change the capitalisation e.g. userEnteredFormat, it never works, but doesn’t complain. If I enter some gibberish like “UserEnteredFromage” then I get an exception (fair enough, I’d expect that!)

    But how can I edit the background colour without wiping out the cell’s value?
    (It also resets/defaults/”wipes out” other aspects of format, e.g. font, alignment, border)

    I’m not familiar with Google Scripts, Node.js, PHP, Python or Ruby, just C#,…so the Google Sheets API documentation which seem to be mostly written for these other languages are a little hard to follow sometimes. For FieldMask on the UpdateCellsRequest page, the link seems to take me to something in the Protocol Buffers API documentation, which I don’t think is right.

    Can you help? – Many thanks!