### 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 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 ListDocs API Extract Body