### Install Google Docs API Client Library for Python using Setuptools Source: https://developers.google.com/workspace/docs/api/how-tos/libraries Use Setuptools to install or upgrade the Google API client library for Python. This is an alternative to pip for managed installation. ```bash easy_install --upgrade google-api-python-client ``` -------------------------------- ### Install http-server Package Source: https://developers.google.com/workspace/docs/api/quickstart/js Install the http-server package using npm. This is a prerequisite for starting a local web server to run the sample. ```bash npm install http-server ``` -------------------------------- ### Install Google Docs API Client Library for Python Manually Source: https://developers.google.com/workspace/docs/api/how-tos/libraries Manually install the Python client library by downloading, unpacking, and running the setup script. ```bash python setup.py install ``` -------------------------------- ### Start Local Web Server Source: https://developers.google.com/workspace/docs/api/quickstart/js Start a local web server on port 8000 using npx. This command is used to serve the sample application from your working directory. ```bash npx http-server -p 8000 ``` -------------------------------- ### Initialize Google Docs API Quickstart Source: https://developers.google.com/workspace/docs/api/quickstart/python The base code for the quickstart application, including necessary imports and the definition of read-only document scopes. ```python import os.path from google.auth.transport.requests import Request from google.oauth2.credentials import Credentials from google_auth_oauthlib.flow import InstalledAppFlow from googleapiclient.discovery import build from googleapiclient.errors import HttpError # If modifying these scopes, delete the file token.json. SCOPES = ["https://www.googleapis.com/auth/documents.readonly"] ``` -------------------------------- ### Install Google Docs API client libraries Source: https://developers.google.com/workspace/docs/api/quickstart/nodejs Install the necessary Google APIs and local authentication packages via npm to enable API interaction. ```bash npm install googleapis@105 @google-cloud/local-auth@2.1.0 --save ``` -------------------------------- ### Execute Python Quickstart Script Source: https://developers.google.com/workspace/docs/api/quickstart/python Command to run the authentication and API retrieval script from the terminal. ```bash python3 quickstart.py ``` -------------------------------- ### Install Google Docs API Client Library for Python using pip Source: https://developers.google.com/workspace/docs/api/how-tos/libraries Use pip to install or upgrade the Google API client library for Python. This is the preferred method for managed installation. ```bash pip install --upgrade google-api-python-client ``` -------------------------------- ### Run Gradle Project Source: https://developers.google.com/workspace/docs/api/quickstart/java Execute the Gradle build to run the Java quickstart application. This command initiates the application, which may prompt for authorization on the first run. ```bash gradle run ``` -------------------------------- ### Install Google Docs API Client Gem using RubyGems Source: https://developers.google.com/workspace/docs/api/how-tos/libraries Install the Google API Client Library for Ruby using RubyGems. You may need to prepend this command with `sudo`. ```bash gem install google-api-client ``` -------------------------------- ### Google Docs API Quickstart Implementation Source: https://developers.google.com/workspace/docs/api/quickstart/go A complete Go application that handles OAuth 2.0 authentication and retrieves a document title using the Google Docs API. ```go package main import ( "context" "encoding/json" "fmt" "log" "net/http" "os" "golang.org/x/oauth2" "golang.org/x/oauth2/google" "google.golang.org/api/docs/v1" "google.golang.org/api/option" ) // Retrieves a token, saves the token, then returns the generated client. func getClient(config *oauth2.Config) *http.Client { tokFile := "token.json" tok, err := tokenFromFile(tokFile) if err != nil { tok = getTokenFromWeb(config) saveToken(tokFile, tok) } return config.Client(context.Background(), tok) } // Requests a token from the web, then returns the retrieved token. func getTokenFromWeb(config *oauth2.Config) *oauth2.Token { authURL := config.AuthCodeURL("state-token", oauth2.AccessTypeOffline) fmt.Printf("Go to the following link in your browser then type the "+ "authorization code: \n%v\n", authURL) var authCode string if _, err := fmt.Scan(&authCode); err != nil { log.Fatalf("Unable to read authorization code: %v", err) } tok, err := config.Exchange(oauth2.NoContext, authCode) if err != nil { log.Fatalf("Unable to retrieve token from web: %v", err) } return tok } // Retrieves a token from a local file. func tokenFromFile(file string) (*oauth2.Token, error) { f, err := os.Open(file) defer f.Close() if err != nil { return nil, err } tok := &oauth2.Token{} err = json.NewDecoder(f).Decode(tok) return tok, err } // Saves a token to a file path. func saveToken(path string, token *oauth2.Token) { fmt.Printf("Saving credential file to: %s\n", path) f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600) defer f.Close() if err != nil { log.Fatalf("Unable to cache OAuth token: %v", err) } json.NewEncoder(f).Encode(token) } func main() { ctx := context.Background() b, err := os.ReadFile("credentials.json") if err != nil { log.Fatalf("Unable to read client secret file: %v", err) } // If modifying these scopes, delete your previously saved token.json. config, err := google.ConfigFromJSON(b, "https://www.googleapis.com/auth/documents.readonly") if err != nil { log.Fatalf("Unable to parse client secret file to config: %v", err) } client := getClient(config) srv, err := docs.NewService(ctx, option.WithHTTPClient(client)) if err != nil { log.Fatalf("Unable to retrieve Docs client: %v", err) } // Prints the title of the requested doc: // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit docId := "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE" doc, err := srv.Documents.Get(docId).Do() if err != nil { log.Fatalf("Unable to retrieve data from document: %v", err) } fmt.Printf("The title of the doc is: %s\n", doc.Title) } ``` -------------------------------- ### Specific List Properties Example (kix.ussavk43dhsk) Source: https://developers.google.com/workspace/docs/api/samples/output-json?hl=ar This snippet shows a specific example of list properties configuration identified by 'kix.ussavk43dhsk', detailing various nesting levels with different glyph symbols and indentation. ```APIDOC ## Specific List Properties Example (kix.ussavk43dhsk) ### Description This example demonstrates a specific list properties configuration, including multiple nesting levels with distinct bullet symbols and indentation settings. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **listProperties** (object) - Required - Contains the configuration for list properties. - **nestingLevels** (array) - Required - An array of objects, where each object defines the properties for a nesting level. - **bulletAlignment** (string) - Optional - Alignment of the bullet (e.g., "START", "END"). - **glyphSymbol** (string) - Optional - The symbol used for the bullet point (e.g., "●", "○", "■"). - **glyphFormat** (string) - Optional - The format string for the glyph. - **indentFirstLine** (object) - Optional - Specifies the indentation for the first line. - **magnitude** (number) - Required - The magnitude of the indentation. - **unit** (string) - Required - The unit of measurement (e.g., "PT"). - **indentStart** (object) - Optional - Specifies the starting indentation. - **magnitude** (number) - Required - The magnitude of the indentation. - **unit** (string) - Required - The unit of measurement (e.g., "PT"). - **textStyle** (object) - Optional - Defines the text style. - **underline** (boolean) - Optional - Whether the text should be underlined. - **startNumber** (integer) - Optional - The starting number for numbered lists. ### Request Example ```json { "kix.ussavk43dhsk": { "listProperties": { "nestingLevels": [ { "bulletAlignment": "START", "glyphSymbol": "●", "glyphFormat": "%0", "indentFirstLine": { "magnitude": 18.0, "unit": "PT" }, "indentStart": { "magnitude": 36.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 }, { "bulletAlignment": "START", "glyphSymbol": "○", "glyphFormat": "%1", "indentFirstLine": { "magnitude": 54.0, "unit": "PT" }, "indentStart": { "magnitude": 72.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 }, { "bulletAlignment": "START", "glyphSymbol": "■", "glyphFormat": "%2", "indentFirstLine": { "magnitude": 90.0, "unit": "PT" }, "indentStart": { "magnitude": 108.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 } ] } } } ``` ### Response #### Success Response (200) - **kix.ussavk43dhsk** (object) - Contains the specific list properties configuration. #### Response Example ```json { "kix.ussavk43dhsk": { "listProperties": { "nestingLevels": [ { "bulletAlignment": "START", "glyphSymbol": "●", "glyphFormat": "%0", "indentFirstLine": { "magnitude": 18.0, "unit": "PT" }, "indentStart": { "magnitude": 36.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 }, { "bulletAlignment": "START", "glyphSymbol": "○", "glyphFormat": "%1", "indentFirstLine": { "magnitude": 54.0, "unit": "PT" }, "indentStart": { "magnitude": 72.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 }, { "bulletAlignment": "START", "glyphSymbol": "■", "glyphFormat": "%2", "indentFirstLine": { "magnitude": 90.0, "unit": "PT" }, "indentStart": { "magnitude": 108.0, "unit": "PT" }, "textStyle": { "underline": false }, "startNumber": 1 } ] } } } ``` ``` -------------------------------- ### Batch Update Request Example Source: https://developers.google.com/workspace/docs/api/how-tos/batch This example demonstrates how to construct a batch update request for the Google Docs API, including adding text and formatting it. All subrequests are applied atomically. ```json { "requests": [ { "insertText": { "location": { "index": 1 }, "text": "New bold text." } }, { "updateTextStyle": { "textStyle": { "bold": true }, "range": { "startIndex": 1, "endIndex": 19 } } } ] } ``` -------------------------------- ### Initialize Google Docs API Quickstart Source: https://developers.google.com/workspace/docs/api/quickstart/js A complete HTML file containing the necessary scripts to authorize users and retrieve a document title. Replace the placeholder CLIENT_ID and API_KEY constants with your own credentials from the Google Cloud Console. ```html Google Docs API Quickstart

Google Docs API Quickstart



    
    
    
  

```

--------------------------------

### Google Docs API Authentication and Setup - Python

Source: https://developers.google.com/workspace/docs/api/samples/extract-text?hl=bn

Provides necessary imports and boilerplate for authenticating with the Google Docs API and setting up the service client. Includes scopes for reading and writing documents.

```python
# Copyright 2026 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""
Recursively extracts the text from a Google Doc.
"""
import os.path

import googleapiclient.discovery as discovery
from google.auth.transport.requests import Request
from google.oauth2.credentials import Credentials
from google_auth_oauthlib.flow import InstalledAppFlow
from googleapiclient.errors import HttpError

```

--------------------------------

### Java Quickstart for Google Docs API

Source: https://developers.google.com/workspace/docs/api/quickstart/java

This Java code sets up authentication and retrieves the title of a Google Document using the Docs API. Ensure you have a 'credentials.json' file and the necessary dependencies.

```java
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp;
import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver;
import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow;
import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets;
import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport;
import com.google.api.client.http.javanet.NetHttpTransport;
import com.google.api.client.json.JsonFactory;
import com.google.api.client.json.gson.GsonFactory;
import com.google.api.client.util.store.FileDataStoreFactory;
import com.google.api.services.docs.v1.Docs;
import com.google.api.services.docs.v1.DocsScopes;
import com.google.api.services.docs.v1.model.Document;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.security.GeneralSecurityException;
import java.util.Collections;
import java.util.List;

/* class to demonstrate use of Docs get documents API */
public class DocsQuickstart {
  /**
   * Application name.
   */
  private static final String APPLICATION_NAME = "Google Docs API Java Quickstart";
  /**
   * Global instance of the JSON factory.
   */
  private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance();
  /**
   * Directory to store authorization tokens for this application.
   */
  private static final String TOKENS_DIRECTORY_PATH = "tokens";
  private static final String DOCUMENT_ID = "195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE";

  /**
   * Global instance of the scopes required by this quickstart.
   * If modifying these scopes, delete your previously saved tokens/ folder.
   */
  private static final List SCOPES =
      Collections.singletonList(DocsScopes.DOCUMENTS_READONLY);
  private static final String CREDENTIALS_FILE_PATH = "/credentials.json";

  /**
   * Creates an authorized Credential object.
   *
   * @param HTTP_TRANSPORT The network HTTP Transport.
   * @return An authorized Credential object.
   * @throws IOException If the credentials.json file cannot be found.
   */
  private static Credential getCredentials(final NetHttpTransport HTTP_TRANSPORT)
      throws IOException {
    // Load client secrets.
    InputStream in = DocsQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH);
    if (in == null) {
      throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH);
    }
    GoogleClientSecrets clientSecrets = 
        GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in));

    // Build flow and trigger user authorization request.
    GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder(
        HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, SCOPES) 
        .setDataStoreFactory(new FileDataStoreFactory(new java.io.File(TOKENS_DIRECTORY_PATH)))
        .setAccessType("offline")
        .build();
    LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build();
    Credential credential = new AuthorizationCodeInstalledApp(flow, receiver).authorize("user");
    //returns an authorized Credential object.
    return credential;
  }

  public static void main(String... args) throws IOException, GeneralSecurityException {
    // Build a new authorized API client service.
    final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport();
    Docs service = new Docs.Builder(HTTP_TRANSPORT, JSON_FACTORY, getCredentials(HTTP_TRANSPORT))
        .setApplicationName(APPLICATION_NAME)
        .build();

    // Prints the title of the requested doc:
    // https://docs.google.com/document/d/195j9eDD3ccgjQRttHhJPymLJUCOUjs-jmwTrekvdjFE/edit
    Document response = service.documents().get(DOCUMENT_ID).execute();
    String title = response.getTitle();

    System.out.printf("The title of the doc is: %s\n", title);
  }
}
```

--------------------------------

### Full Resource Response Example (Demo API)

Source: https://developers.google.com/workspace/docs/api/how-tos/performance

This JSON structure represents a full response from a generic API, containing various fields including nested objects and arrays. It is shown for comparison with partial responses.

```json
{
  "kind": "demo",
  ...
  "items": [
  {
    "title": "First title",
    "comment": "First comment.",
    "characteristics": {
      "length": "short",
      "accuracy": "high",
      "followers": ["Jo", "Will"],
    },
    "status": "active",
    ...
  },
  {
    "title": "Second title",
    "comment": "Second comment.",
    "characteristics": {
      "length": "long",
      "accuracy": "medium"
      "followers": [ ],
    },
    "status": "pending",
    ...
  },
  ...
  ]
}
```

--------------------------------

### Partial Resource Response Example (Demo API)

Source: https://developers.google.com/workspace/docs/api/how-tos/performance

This JSON structure represents a partial response from a generic API, containing only the fields specified in the 'fields' parameter of the request. It includes the 'kind' and a reduced set of 'items' data.

```json
{
  "kind": "demo",
  "items": [{
    "title": "First title",
    "characteristics": {
      "length": "short"
    }
  }, {
    "title": "Second title",
    "characteristics": {
      "length": "long"
    }
  },
  ...
  ]
}
```

--------------------------------

### Run the Sample Application

Source: https://developers.google.com/workspace/docs/api/quickstart/go

Command to execute the Go application.

```bash
go run quickstart.go
```

--------------------------------

### Initialize Go Project Environment

Source: https://developers.google.com/workspace/docs/api/quickstart/go

Commands to create a directory, initialize a module, and fetch required Google API and OAuth2 dependencies.

```bash
mkdir quickstart
```

```bash
cd quickstart
```

```bash
go mod init quickstart
```

```bash
go get google.golang.org/api/docs/v1
go get golang.org/x/oauth2/google
```

--------------------------------

### GET /v1/documents

Source: https://developers.google.com/workspace/docs/api/reference/rest/v1/documents

Gets the latest version of the specified document.

```APIDOC
## GET /v1/documents

### Description
Gets the latest version of the specified document.

### Method
GET

### Endpoint
/v1/documents/{documentId}
```

--------------------------------

### Initialize Gradle Project Structure

Source: https://developers.google.com/workspace/docs/api/quickstart/java

Creates the base directory structure and initializes a basic Gradle project.

```bash
gradle init --type basic
mkdir -p src/main/java src/main/resources
```

--------------------------------

### Get and Print Google Document (Python)

Source: https://developers.google.com/workspace/docs/api/samples/output-json?hl=fa

Performs a 'get' request to the Google Docs API to retrieve a document and prints the result as formatted JSON. Ensure DOCUMENT_ID is set correctly.

```python
# Do a document "get" request and print the results as formatted JSON
result = service.documents().get(documentId=DOCUMENT_ID, includeTabsContent=True).execute()
print(json.dumps(result, indent=4, sort_keys=True))
```

--------------------------------

### GET /documents.get

Source: https://developers.google.com/workspace/docs/api/concepts/request-response?hl=es-419

Retrieves the full content and formatting of a specified document.

```APIDOC
## GET documents.get

### Description
Returns a full instance of the specified document. Note: This method cannot be used for published documents.

### Method
GET

### Endpoint
documents.get

### Parameters
#### Path Parameters
- **documentId** (string) - Required - The ID of the document to retrieve.
```

--------------------------------

### GET /documents/{documentId}

Source: https://developers.google.com/workspace/docs/api/reference/rest/v1/documents/get

Retrieves the latest version of the specified Google Document.

```APIDOC
## GET https://docs.googleapis.com/v1/documents/{documentId}

### Description
Gets the latest version of the specified document.

### Method
GET

### Endpoint
https://docs.googleapis.com/v1/documents/{documentId}

### Parameters
#### Path Parameters
- **documentId** (string) - Required - The ID of the document to retrieve.

#### Query Parameters
- **suggestionsViewMode** (enum) - Optional - The suggestions view mode to apply to the document.
- **includeTabsContent** (boolean) - Optional - Whether to populate the Document.tabs field instead of the text content fields.

### Response
#### Success Response (200)
- **Document** (object) - An instance of the Document resource.
```

--------------------------------

### Initialize Gradle Project

Source: https://developers.google.com/workspace/docs/api/quickstart/java?hl=zh-cn

Creates a new basic Gradle project and necessary directories for the Java application.

```bash
gradle init --type basic
mkdir -p src/main/java src/main/resources 

```

--------------------------------

### Installazione delle librerie client Google

Source: https://developers.google.com/workspace/docs/api/quickstart/python?hl=it

Comando per installare le librerie necessarie per l'interazione con le API di Google Workspace tramite Python.

```bash
python3 -m pip install --upgrade google-api-python-client google-auth-httplib2 google-auth-oauthlib
```

--------------------------------

### SectionType Enum

Source: https://developers.google.com/workspace/docs/api/reference/rest/v1/documents

Represents how the start of the current section is positioned relative to the previous section.

```APIDOC
## SectionType

### Description
Represents how the start of the current section is positioned relative to the previous section.

### Enums
- `SECTION_TYPE_UNSPECIFIED`: The section type is unspecified.
- `CONTINUOUS`: The section starts immediately after the last paragraph of the previous section.
- `NEXT_PAGE`: The section starts on the next page.
```

--------------------------------

### Get document without suggestions

Source: https://developers.google.com/workspace/docs/api/how-tos/suggestions

Retrieve a document with suggestions rejected using the PREVIEW_WITHOUT_SUGGESTIONS mode.

```java
final string SUGGEST_MODE = "PREVIEW_WITHOUT_SUGGESTIONS";
Document doc =
    service
        .documents()
        .get(DOCUMENT_ID)
        .setIncludeTabsContent(true)
        .setSuggestionsViewMode(SUGGEST_MODE)
        .execute();
```

```python
SUGGEST_MODE = "PREVIEW_WITHOUT_SUGGESTIONS"
result = (
  service.documents()
  .get(
      documentId=DOCUMENT_ID,
      includeTabsContent=True,
      suggestionsViewMode=SUGGEST_MODE,
  )
  .execute()
)
```

--------------------------------

### Initialize Google Docs API in JavaScript

Source: https://developers.google.com/workspace/docs/api/samples/output-json?hl=de

Sets up the Google API client library for browser-based interaction. Requires valid Client ID and API Key configuration.

```html


  
    
      Docs API Extract Body
    
    
  
  
    

Docs API Extract Body