How to access Google APIs and services

For a side project of mine, I needed to access Google APIs, more precisely, I needed Google Tasks API access. This tutorial will show how to access google APIs and services.

The easiest way to access the various Google APIs is to use one of their language-specific wrappers. These will require you to provide a client secrets file. This file will contain all the information to access the services you enabled.  All the backend configuration is done through Google APIs Console.

Warning: It’s not quite clear if this file is safe to be shared with anyone (aka, checked into a public repository, distributed to clients, etc.). The way I personally see it is that this file allows clients to connect to the Google services you enable. Some of these services have a quota, others are simply paid. Therefore, anyone getting your file can easily go over your quota or get you billed quite a bit in a month. Basically, what I am saying is that I would not distribute this file to other people.

Enable needed APIs

After creating your project, the first thing you’ll need to do is select which APIs you want to use. In order to do so, simply go into the Dashboard section and hit the Enable APIs and Services button. The next page will allow you to search and select which APIs you want to enable. Once an API is selected, a page describing it and allowing you to enable the API will be shown. Check this page carefully, some APIs have quotas or are paid services.


Getting to the enable APIs page

Getting to the enable APIs page

Searching for APIs to enable

Searching for APIs to enable

Enabling an API

Enabling an API


Setup OAuth Consent Screen

The client secrets file is only one part of the OAuth process. It will be used to access your configuration, quotas, make you pay for services, etc. It is provided by the software/tool/website maker. The second part of the process is the client information. This will be provided by the user of the software/tool/website and will allow the maker to access some information about the user.

For example, a website could request access to the Google Drive content of a user. The APIs quotas that will be used are the ones from the owner of the website, but the information accessed will be the one of the user.

Before the website is allowed to access information about the client, the client must consent to share this information. Google requires you to customize this consent screen before it can be used. In order to do so, you will need to go to the Credentials section, then select the OAuth Consent Screen tab. In there, you will be able to customize quite a few information to make your consent screen nice and professional. The bare minimum is to select an email address and a product name. Both of these will be shown to the user when asking him to consent to the sharing his information.


Customizing the consent screen

Customizing the consent screen


Create credentials and download client secrets file

All the grunt work is now done for your project. The last piece of the puzzle is to create the credential and get the file. In order to create the credentials, you will need to go to the Credentials section and hit the Create Credentials button. In the submenu, you will need to select OAuth client ID. The next page will allow you to select the type of application. According to the Google documentation, there should be an Installed application option in there. That option would have been perfect for me (working on a command line tool here). In the end, I went with the only thing that made sense: Other.

Once your credential is created, simply go to the Credentials section, find the credential you want to use and hit the download icon. All done!


Creating a new credential

Creating a new credential

Specifying the credential information

Specifying the credential information

Downloading client secrets file

Downloading client secrets file


Sources

Tagged . Bookmark the permalink.

Leave a Reply