Environment Setup ✅ Beginner

Google API Key Complete Guide: Essential for Connecting OpenClaw to Google Drive / Gmail

A step-by-step guide to applying for a Google Cloud API Key — solving the most common sticking point when connecting OpenClaw to Google services.

📝 建立:2026年2月24日 ✅ 最後驗證:2026年2月24日
鴨編 卡住很正常——點段落旁的 😵 卡關 讓我們知道,或直接往下滾到問答區發問。 也可以用 👍 看懂 / 😢 看不懂 告訴我們哪裡寫得好、哪裡要改。

Why Are You Reading This?

You want to use OpenClaw to connect to Google Drive or Gmail, but you got stuck at the API Key setup step.

That’s completely normal. The Google Cloud Console interface is very unfriendly for people without a technical background, and many video tutorials either skip this step or rush through it.

This article will walk you through it step by step, including the 5 most common mistakes.


What You’ll Need

  • A Google account (your regular Gmail works fine)
  • About 15-20 minutes
  • OpenClaw already installed (if not, check out the Installation Guide first)

Step 1: Enter Google Cloud Console

  1. Open your browser and go to console.cloud.google.com
  2. Sign in with your Google account
  3. If this is your first time, you’ll see a “Terms of Service” screen — check the box and click “Agree and Continue”

Google Cloud Console home screen

Duck Editor Quick tip: If you have multiple Google accounts, make sure you’re using the right one. You can switch accounts from the profile icon in the top-right.


Step 2: Create a New Project

  1. Click the project selector at the top (it may show “My First Project” or “Select a project”)

Click the project selector at the top

  1. Click “New Project”

New Project button

  1. For the project name, enter: openclaw-integration (or any name you like)
  2. Click “Create”

Enter project name and create

  1. Wait a few seconds — once the project is created, it should switch automatically

🚨 Common Mistake #1: Not Switching to the New Project

After creating the project, the project name at the top may not switch automatically. Manually click the project selector and confirm you’re under the openclaw-integration project.

Confirm you've switched to the correct project


Step 3: Enable the Required APIs

Depending on which services you want to connect, you’ll need to enable different APIs:

Connecting Google Drive

  1. In the left menu, find “APIs & Services” → “Library”

    Enable Google Drive API

    Enable Google Drive API

  1. Search for Google Drive API
  2. Click into it and press “Enable”

Enable Google Drive API

Enable Google Drive API

Enable Google Drive API

Connecting Gmail

  1. Same as above, search for Gmail API
  2. Click into it and press “Enable”

Enable Gmail API

Enable Gmail API

Enable Gmail API

Duck Editor Need both? Just enable both — they don’t conflict.

🚨 Common Mistake #2: Enabling the Wrong API

Google has many APIs with similar names. Make sure you enable:

  • Google Drive API (NOT Google Drive Activity API)
  • Gmail API (NOT other Google Workspace APIs)

This is the step many people find most confusing, but just follow along and you’ll be fine.

  1. In the left menu, find “APIs & Services” → “OAuth consent screen”
  2. Select “External,” then click “Create”
  3. Fill in the following information:
  • App name: OpenClaw (name it whatever you like)
  • User support email: Select your Gmail
  • Developer contact information: Enter your Gmail
  1. Leave other fields empty and click “Save and Continue”

  2. On the “Scopes” page, just click “Save and Continue”

  3. On the “Test users” page:

    • Click “Add users”
    • Enter your own Gmail address
    • Click “Save and Continue”
  1. Review the summary page and finish

🚨 Common Mistake #3: Forgetting to Add a Test User

If you don’t add your own email as a test user, you’ll get a 403 access_denied error later. Make sure to add it!


Step 5: Create Credentials (API Key + OAuth Client)

Create an OAuth Client ID

  1. In the left menu, go to “APIs & Services” → “Credentials”
  2. Click “Create Credentials” → “OAuth client ID”

Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type Select External user type 3. For application type, select “Desktop app”

  1. Enter any name, then click “Create”
  2. A dialog will appear showing:
    • Client ID
    • Client secret
  3. Copy both of these! Even better, click “Download JSON” to download a credentials.json file

Select External user type Select External user type Select External user type Select External user type

🚨 Common Mistake #4: Selecting the Wrong Application Type

If you select “Web application” instead of “Desktop app,” OpenClaw won’t be able to complete the OAuth flow locally.


Step 6: Configure in OpenClaw

  1. Place the downloaded credentials.json in OpenClaw’s config folder
  2. Add the following to OpenClaw’s config file:
{
  "google": {
    "credentials_path": "./credentials.json",
    "scopes": [
      "https://www.googleapis.com/auth/drive.readonly",
      "https://www.googleapis.com/auth/gmail.readonly"
    ]
  }
}
  1. Restart OpenClaw
  2. The first time you use it, a browser window will pop up asking you to authorize — just click “Allow”

🚨 Common Mistake #5: Scope Too Broad or Too Narrow

  • drive.readonly = Can only read Google Drive files (safe)
  • drive = Can read, write, and delete all files (higher risk)
  • Start with readonly, and expand permissions once you’ve confirmed it works

Done! Verify It Works

Try this command in OpenClaw:

List the 5 most recently modified files in my Google Drive

If you see a file list, congratulations 🚀 Launch successful!

If you’re still having issues, here are the common debugging steps:

  1. Confirm the credentials.json path is correct
  2. Confirm the APIs are enabled (Step 3)
  3. Confirm you added yourself as a test user (Step 4)
  4. Confirm the application type is “Desktop app” (Step 5)
  5. Try deleting token.json and re-authorizing

Next Steps

Now that your API Key is set up, here’s what’s next:


Still Stuck?

Click the ”😵 I’m stuck” button below to let us know, or head to the Home Discussion section to ask a question — include any error messages and we’ll help you figure it out!

這篇文章對你有幫助嗎?

💬 問答區

卡關了?直接在這裡問,其他讀者和作者都能幫忙解答。

載入中...