Google Cloud Cloud APIs [GoogleDrive for Arduino program]

In the Video

Japanese【日本語】

English

1. Overview

Using the GoogleDrive API [API] with a software program. In my case, I do electronic work and a program that saves JPEG images captured by the camera to GoogleDrive.

If you want to know details, Please refer to Google Support Site.

OAuth 2.0 for TV and Limited-Input Device Applications  |  Authorization  |  Google for Developers

2. Applied Practical

IoT Camera(ESP32 and OV2640) get JPEG image and Send to Google Cloud[Drive] by HTTP-POST. (See below) This Electric work is another post.

3. Google Cloud Setting

The following items must be obtained from Google Cloud.

1) OAUTH client ID
2) Secret key
3) User/device code
4) verification URL

For Google cloud settings, follow the steps below

Step1. Get OAUTH client ID and secret key from Google Cloud Console
Step2. Acquire user/device code and verification URL with Curl command (OAuth authentication)
Step3. Access the obtained verification URL with a web browser and enter the user code to authorize
Step4. Get a refresh token by POSTing the device code, client ID and secret key with the Curl command

Details are provided below.

Step1. Get OAUTH client ID and secret key from Google Cloud Console

1) Access to Google Developer Console and Create a new project. Input the Project name(Any name is OK), Then Click “Create”.

2) Select “APIs & Services” in Left Menu, and Select “Credentials”.

3) Select “CREATE CREDENTIALS” and Select “OAuth client ID”.

4) Click “CONFIGURE CONSENT SCREEN”.

5) Select “External” and Click “CREATE”.

6-1) Input App Name(Any name is OK) and E-mail.

*Note: Don’t Use “Google” Word at App Name.

6-2) And Input E-mail and Click “SAVE AND CONTINUE”.

7) Click “SAVE AND CONTINUE”.

8) Click “SAVE AND CONTINUE”.

Back to the Dashboard.

9) Click “PUBLISH APP” and Click “CONFIRM” on the next pop-up screen. [Menu: OAuth consent screen]

“OAuth consent screen” is completed, then go to Next.

10) Select “CREATE CREDENTIALS” and Select “OAuth client ID”.

11) Select App Type “TVs and limited Input devices” and Input the OAuth client name(Any name is OK).

12) Get “Client ID” and “Client Secret”.

13) Next Enable API Service, so select “APIs & Services” and select “Enable APIs & Services”.

14) Click “ENABLE APIS AND SERVICES”.

15) Input “Drive” and search.

16) Click “Google Drive API”.

17) Click “ENABLE”.

This section is Completed.

Step2. Acquire user/device code and verification URL with Curl command

Get the code and verification URL with the Curl command. The curl command is below.
Note: Replace “[ClientID]” with the ID you got.

curl -d "client_id=[Client ID] &scope=https://www.googleapis.com/auth/drive.file" https://oauth2.googleapis.com/device/code

Windows11 example)
Start “the Command prompt” App and Execute Curl command as below.

Step3. Access the obtained verification URL with a web browser and enter the user code to authorize

1) Access the obtained “verification_url” (such as “https://www.google.com/device”) at 3-1-1 with a web browser (such as Chrome), enter the user code when asked for a code, and click “Next”.

2) Click Google Account that you use on this project.

3) Click “Allow”.

This section is completed.

Step4. Get a refresh token by POSTing the device code, client ID and secret key with the Curl command

Execute with the Curl command to get a refresh token. The curl command is below.
Note1: Replace “[ClientID]”, “[ClientSecret]”, “[DeviceCODE]” with the ID you got.
Note2: DeviceCODE will expire as per the time responded(etc. 1800 sec) [see 3-1-2]. so you Must execute this curl command within the time (etc. 1800 sec) from 3-1-2.

curl -d "client_id=[ClientID]&client_secret=[ClientSecret]&
         device_code=[DeviceCODE]&
         grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Adevice_code"
         -H "Content-Type: application/x-www-form-urlencoded"
         https://oauth2.googleapis.com/token

Windows11 example)
Start “the Command prompt” App and Execute Curl command as below.

The Refresh token was obtained. Then We set this Refresh code to Arduino Program.

Comments

Copied title and URL