Using the Natural Language API from Google Docs
Solution for Using the Natural Language API from Google Docs. 1 lab: GSP126. Fast copy-paste commands for Google Cloud.
GSP126 — Using the Natural Language API from Google Docs
Estimated time: 10 minutes
# 📄 Using the Natural Language API from Google Docs > ⚠️ **Disclaimer:** This is an independent, community-made walkthrough created to help you understand how the Google Cloud Natural Language API can be integrated with Google Docs using Apps Script. Attempt the lab yourself first and use this guide as a learning aid rather than as a shortcut to skip the underlying concepts. This guide is intended for educational purposes, certification preparation, and hands-on practice with Google Cloud and
# ==============================================================================
# Color Variables & Branding
# ==============================================================================
GREEN='\e[1;32m'
CYAN='\e[1;36m'
YELLOW='\e[1;33m'
MAGENTA='\e[1;35m'
RED='\e[1;31m'
RESET='\e[0m'
BOLD='\e[1m'
clear
echo -e "${CYAN}${BOLD}"
cat << "EOF"
____ _ _ _ __ ___
/ __ \ | | (_) | / _| / _ \
| | | |_ __| |__ _| |_ ___ | |_ | | | |_ __ ___
| | | | '__| '_ \| | __| / _ \ | _| | | | | '_ \/ __|
| |__| | | | |_) | | |_ | (_) || | | |_| | |_) \__ \
\____/|_| |_.__/|_|\__| \___/ |_| \___/| .__/|___/
| |
|_|
EOF
echo -e "${RESET}"
echo -e "${MAGENTA}${BOLD}>>> ORBIT OF OPS: GSP126 PART 1 INITIALIZED <<<${RESET}\n"
echo -e "${YELLOW}${BOLD}[Orbit of Ops] Auto-fetching Project...${RESET}"
export PROJECT_ID=$(gcloud config get-value project 2>/dev/null)
if [[ -z "$PROJECT_ID" ]]; then
export PROJECT_ID=$DEVSHELL_PROJECT_ID
fi
echo -e "✅ Project ID: ${GREEN}$PROJECT_ID${RESET}\n"
echo -e "${CYAN}${BOLD}[Orbit of Ops] Task 1: Enabling Natural Language & API Key Services...${RESET}"
gcloud services enable language.googleapis.com apikeys.googleapis.com || true
echo -e "${YELLOW}${BOLD}[Orbit of Ops] Task 2: Generating Restricted API Key...${RESET}"
# Generate the key and restrict it specifically to the Natural Language API
gcloud services api-keys create --display-name="NL_API_KEY" --api-target=service=language.googleapis.com || true
export KEY_NAME=$(gcloud services api-keys list --format="value(name)" --filter "displayName=NL_API_KEY" | head -n 1)
export API_KEY=$(gcloud services api-keys get-key-string $KEY_NAME --format="value(keyString)")
echo -e "✅ Your API Key has been generated: ${GREEN}$API_KEY${RESET}\n"
echo -e "${GREEN}${BOLD}✅ Part 1 Complete. Please click 'Check my progress' on Task 2 in the lab window!${RESET}"