Sitemap / Advertise

Information



Tags



Share

How to install the Google Client Library in Python on Raspberry Pi

Advertisement:


read_later

Read Later

Keywords



Keywords



read_later

Read Later

Information

Tags

Share





Advertisement

Advertisement




Definition

In this tutorial, I will show you how to install the Google Client Library for Python to create projects using the vast breadth of applications and APIs provided by Google, such as Google Sheets API, YouTube API, or Gmail API.

Instructions:

- Open the terminal and enter the command below (it will take some time to install all packages):

$ sudo pip install --upgrade google-api-python-client

article-image
Figure - 130.1

- If requested, you may need to install the oauth2client module.

$ sudo pip install --upgrade oauth2client

- Before using the Google Client Library for Python, you need to register an application on the Google API Console to run the Google APIs Client Library for Python properly, and your application must have authorization credentials to be able to use the requested APIs provided by Google.

- To create a new application, go to the Google API Console and click to the 'New Project' button.

article-image
Figure - 130.2

Creating Credentials after Installing the Google Client Library for Python

Each request to an API that is represented in the console must include a unique identifier. Unique identifiers enable the console to tie requests to specific projects to monitor traffic and enforce quotas.

Google supports two mechanisms for creating unique identifiers:

OAuth 2.0 client IDs: For applications that use the OAuth 2.0 protocol to call Google APIs, you can use an OAuth 2.0 client ID to generate an access token. The token contains a unique identifier. See Setting up OAuth 2.0 for more information.

API keys: An API key is a unique identifier that you generate using the console. Using an API key does not require user action or consent. API keys do not grant access to any account information, and are not used for authorization(1).

You will need the OAuth 2.0 protocol to utilize all features provided by APIs, such as collecting YouTube views and likes.

To use OAuth 2.0 in your application, you need an OAuth 2.0 client ID, which your application uses when requesting an OAuth 2.0 access token.

To create an OAuth 2.0 client ID in the console(2):

- Go to the API Console.

- From the projects list, select a project or create a new one.

- If the APIs & services page isn't already open, open the console left side menu and select APIs & services.

- On the left, click Credentials.

- Click New Credentials, then select OAuth client ID.

- Note: If you're unsure whether OAuth 2.0 is appropriate for your project, select Help me choose and follow the instructions to pick the right credentials.

- Select the appropriate application type for your project and enter any additional information required. Application types are described in more detail in the following sections.

- If this is your first time creating a client ID, you can also configure your consent screen by clicking Consent Screen. (This procedure explains how to set up the Consent screen.) You won't be prompted to configure the consent screen after you do it the first time.

- Click Create client ID

- To delete a client ID, go to the Credentials page, check the box next to the ID, and then click Delete.

To get more detailed information about the OAuth 2.0 protocol, click here.

Each API requires varied settings and codes and has different guides. By replicating the example codes in the guides in Python, you can use any API easily with your Raspberry Pi without needing a hosting server for your application, including Google Client API.

To inspect the list of all APIs provided by Google and APIs guidelines, click here.

Result:

You can inspect my electronics project in which the YouTube Data API v3 is used to develop a video recoder and uploader GUI with night vision from here.

References

(1) https://support.google.com/googleapi/answer/6158857?hl=en&ref_topic=7013279

(2) https://support.google.com/googleapi/answer/6158849