Google API Reference

Andre Vianna
My Dev Zone
Published in
6 min readMar 9, 2024

Access Token & Refresh Token

Google API Services refer to a collection of APIs (Application Programming Interfaces) provided by Google that allow developers to integrate various Google products and services into their applications. These APIs enable developers to access and utilize functionalities such as authentication, data storage, geolocation, mapping, search, cloud services, and more.

Some key Google API Services include:

1. Google Maps API: Allows developers to embed Google Maps on webpages or in mobile applications, customize maps, and access various map-related services.

2. Google Drive API: Enables developers to interact with Google Drive, allowing users to store and retrieve files, manage permissions, and perform other file-related operations.

3. Google Calendar API: Provides access to Google Calendar data, allowing developers to create, modify, and retrieve calendar events.

4. Google Sheets API: Allows developers to interact with Google Sheets, enabling the creation, modification, and retrieval of spreadsheet data.

5. Google Analytics API: Provides programmatic access to Google Analytics data, allowing developers to retrieve analytics information and integrate it into custom applications.

6. Google Cloud Vision API: Offers image analysis services, including facial recognition, object detection, and optical character recognition (OCR).

7. Google Cloud Speech-to-Text API: Converts spoken language into written text, making it useful for speech recognition applications.

8. Google Cloud Translation API: Enables developers to integrate language translation capabilities into their applications.

9. Google Sign-In API: Allows users to sign in to third-party websites or applications using their Google credentials.

10. Google Identity Platform: Provides authentication and user management services for web and mobile applications.

11. Google Search Console API: Allows developers to access data from Google Search Console, providing insights into website performance on Google Search.

These are just a few examples, and Google offers a wide range of APIs covering various domains. Developers can use these APIs to enhance the functionality of their applications, improve user experiences, and leverage Google’s powerful infrastructure and services. Each API typically comes with its own documentation, usage guidelines, and authentication mechanisms.

1) Create Access Token & Refresh Token

a) Generate client id and secret key.

b) Add Google logged in user as a Test user in consent screen.

c) Generate Authorization Code (One Time)

https://accounts.google.com/o/oauth2/auth?client_id=xxxxxxxx&redirect_uri=http://localhost&response_type=code&scope=https://www.googleapis.com/auth/drive&access_type=offline

d) Generate Refresh Token (One Time)

curl — request POST — data “code=xxxxxxxx&client_id=xxxxxxxxxxxx&client_secret=xxxxxxxxxxxx&redirect_uri=http://localhost&grant_type=authorization_code" https://oauth2.googleapis.com/token

e) Generate Access Token from Refresh token (Always)

curl — request POST — data “client_id=xxxxxxxxxxx&client_secret=xxxxxxxxxxxxxxx&refresh_token=xxxxxxxxxxxxx&grant_type=refresh_token” https://oauth2.googleapis.com/token

Note : Refresh Tokens expire in 1 week if your app is not set as production. Change publishing status of your app from testing to production to use your refresh token always.

The Publishing Status option can be found in ‘Oauth Consent Screen’ which is under API & Services.

2) Google Apps Script

Google Apps Script

Google Apps Script is a scripting language developed by Google that allows users to automate tasks and extend the functionality of various Google Workspace (formerly G Suite) applications such as Google Sheets, Google Docs, Google Drive, and more. It’s a server-side scripting language based on JavaScript, and it provides a way to create custom functions, automate workflows, and interact with Google services programmatically.

Here are some key features and aspects of Google Apps Script:

1. Language: Google Apps Script is based on JavaScript, making it accessible to users who are already familiar with the language. It also includes built-in support for some Google-specific services.

2. Integration with Google Services: Apps Script is tightly integrated with various Google services, allowing developers to automate and extend the functionality of Google Workspace applications. It can interact with Google Sheets, Google Docs, Gmail, Google Drive, Google Calendar, and more.

3. Script Editor: Users can write and edit Google Apps Script code using the online Script Editor provided by Google. The Script Editor is accessible from within Google Workspace applications.

4. Automation and Triggers: Apps Script allows users to automate repetitive tasks by creating scripts that can be triggered by events. For example, a script can be triggered when a form is submitted, a spreadsheet is edited, or a time-driven event occurs.

5. Custom Functions: Users can create custom functions in Google Sheets using Apps Script. These functions can be used to perform specific calculations or operations that are not available through standard spreadsheet functions.

6. Web Apps: Apps Script allows the creation of web applications that can interact with Google services. These web apps can be deployed and accessed through a unique URL.

7. API Access: Apps Script provides access to external APIs, enabling developers to integrate data from other web services into their Google Workspace applications.

8. Google App Maker (Deprecated): While Google App Maker has been deprecated, it was a low-code development environment built on top of Google Apps Script. It allowed users to create custom web applications.

9. Google Cloud Platform Integration: Apps Script can integrate with Google Cloud Platform services, allowing developers to leverage cloud resources and services.

10. Security: Scripts are executed in a secure, sandboxed environment to ensure the safety of user data. Users can control the permissions granted to scripts.

Google Apps Script is a powerful tool for users who want to customize and automate their experience within Google Workspace applications without the need for extensive coding knowledge. It provides a convenient way to extend the functionality of Google services for both personal and business use.

API Google Sheet #1


//ETAPA 1/4*******Configurar Link da Planilha*****

var wbook = SpreadsheetApp.openByUrl('LINK DA PLANILHA');

//ETAPA 2/4*******Configurar nome da Aba que será usada*****

var sheet = wbook.getSheetByName('NOME DA ABA');


function doGet(e) {


var action = e.parameter.action;

if (action == "Read") {
return Read(e);
}

else if (action == "Create") {
return Create(e);
}

else if (action == "Update") {
return Update(e);
}

else if (action == "Delete") {
return Delete(e);
}
}
function Create(e) {

var json = JSON.stringify(e.parameter);
var dados = JSON.parse(json);

//ETAPA 3/4*******Configurar a sequencia das colunas *****

sheet.appendRow([dados.nome, dados.telefone, dados.email, dados.salario]);

return ContentService.createTextOutput([json]).setMimeType(ContentService.MimeType.JSON);
}
function Read(e) {
var rows = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();


var data = [];

for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var record = {};

//ETAPA 4/4*****Edite a linha abaixo com os nomes da colunas que deseja*****

record['Nome'] = row[0];
record['Telefone'] = row[1];
record['Email'] = row[2];
record['Salario'] = row[3];

data.push(record);

}
var result = JSON.stringify(data);

return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}

function Update(e) {
/// Em desenvolvimento
}

function Delete(e) {
/// Em desenvolvimento
}

API Google Sheet #2

//*******Configurar Link da Planilha*****

var wbook = SpreadsheetApp.openByUrl('cole o link da planilha aqui');

//*******Configurar nome da Aba que será usada*****

var sheet = wbook.getSheetByName('cole o nome da aba aqui');

function doGet(e) {

var rows = sheet.getRange(2, 1, sheet.getLastRow() - 1, sheet.getLastColumn()).getValues();
var data = [];

for (var i = 0; i < rows.length; i++) {
var row = rows[i];
var record = {};

//*****Edite a linha abaixo com os nomes da colunas que deseja*****

record['Nome'] = row[0];
record['Data Nascimento'] = row[1];
record['Endereço'] = row[2];

data.push(record);

}
var result = JSON.stringify(data);

return ContentService.createTextOutput(result).setMimeType(ContentService.MimeType.JSON);
}

--

--

Andre Vianna
My Dev Zone

Software Engineer & Data Scientist #ESG #Vision2030 #Blockchain #DataScience #iot #bigdata #analytics #machinelearning #deeplearning #dataviz