google-developer-knowledge-api

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Google Developer Knowledge API

Google Developer Knowledge API

Direct REST API access to Google's public developer documentation without needing the MCP server.
无需MCP服务器,即可通过直接REST API访问谷歌公开开发者文档。

Overview

概述

The Developer Knowledge API provides machine-readable access to Google's developer docs. It offers:
  • SearchDocumentChunks: Find relevant page URIs and content snippets
  • GetDocument: Fetch full content of a single document
  • BatchGetDocuments: Fetch multiple documents at once
Developer Knowledge API 提供了对谷歌开发者文档的机器可读访问方式。它支持:
  • SearchDocumentChunks:查找相关页面URI和内容片段
  • GetDocument:获取单篇文档的完整内容
  • BatchGetDocuments:一次性获取多篇文档

Authentication

身份验证

IMPORTANT: Despite official documentation suggesting API keys work, the API actually requires OAuth2 authentication (access tokens or ADC).
重要提示:尽管官方文档表明API密钥可用,但该API实际上需要OAuth2 authentication(访问令牌或ADC)。

Option 1: Application Default Credentials (Recommended)

选项1:应用默认凭据(推荐)

  1. Install gcloud CLI if not already installed
  2. Run:
    bash
    gcloud auth application-default login
  3. Enable the API in your project:
  1. 若未安装gcloud CLI,请先安装
  2. 运行以下命令:
    bash
    gcloud auth application-default login
  3. 在你的项目中启用该API:

Option 2: Service Account

选项2:服务账号

  1. Create a service account in Google Cloud Console
  2. Download the JSON key file
  3. Set the environment variable:
    bash
    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"
  1. 在Google Cloud控制台中创建服务账号
  2. 下载JSON密钥文件
  3. 设置环境变量:
    bash
    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/service-account.json"

Option 3: Access Token

选项3:访问令牌

Get a token manually:
bash
gcloud auth application-default print-access-token
手动获取令牌:
bash
gcloud auth application-default print-access-token

API Reference

API参考

Base URL:
https://developerknowledge.googleapis.com/v1alpha
All requests require an
Authorization: Bearer <token>
header.
基础URL
https://developerknowledge.googleapis.com/v1alpha
所有请求都需要携带
Authorization: Bearer <token>
请求头。

Search for Document Chunks

搜索文档片段

bash
GET /documents:searchDocumentChunks?query={query}
Parameters:
  • query
    (required): Search query string
  • pageSize
    (optional): Number of results per page
  • pageToken
    (optional): Token for pagination
Response includes:
  • documentChunks[]
    : Array of matching chunks
    • parent
      : Document identifier (use for GetDocument)
    • content
      : Snippet of matching content
    • uri
      : Original documentation URL
bash
GET /documents:searchDocumentChunks?query={query}
参数
  • query
    (必填):搜索查询字符串
  • pageSize
    (可选):每页结果数量
  • pageToken
    (可选):分页令牌
响应包含:
  • documentChunks[]
    :匹配片段的数组
    • parent
      :文档标识符(用于GetDocument接口)
    • content
      :匹配内容的片段
    • uri
      :原始文档URL

Get Single Document

获取单篇文档

bash
GET /{document_name}
Parameters:
  • document_name
    : The
    parent
    value from search results (e.g.,
    documents/developers.google.com/...
    )
Response: Full Markdown content of the document
bash
GET /{document_name}
参数
  • document_name
    :搜索结果中的
    parent
    值(例如:
    documents/developers.google.com/...
响应:文档的完整Markdown内容

Batch Get Documents

批量获取文档

bash
POST /documents:batchGet
Body (JSON):
json
{
  "names": [
    "documents/developers.google.com/path/to/doc1",
    "documents/developers.google.com/path/to/doc2"
  ]
}
Retrieves up to 100 documents in a single call.
bash
POST /documents:batchGet
请求体(JSON):
json
{
  "names": [
    "documents/developers.google.com/path/to/doc1",
    "documents/developers.google.com/path/to/doc2"
  ]
}
单次调用最多可检索100篇文档。

Python Client

Python客户端

See
scripts/developer_knowledge_client.py
for a ready-to-use Python client with automatic OAuth2 handling.
请查看
scripts/developer_knowledge_client.py
获取现成可用的Python客户端,它支持自动OAuth2处理。

Installation Requirements

安装要求

bash
pip install google-auth google-auth-httplib2
Or use the gcloud CLI fallback (no extra dependencies).
bash
pip install google-auth google-auth-httplib2
或者使用gcloud CLI作为备选方案(无需额外依赖)。

Quick Usage

快速使用

python
from developer_knowledge_client import DeveloperKnowledgeClient
python
from developer_knowledge_client import DeveloperKnowledgeClient

Uses Application Default Credentials automatically

自动使用应用默认凭据

client = DeveloperKnowledgeClient()
client = DeveloperKnowledgeClient()

Search for documentation

搜索文档

results = client.search("Cloud Storage buckets") for chunk in results.get("documentChunks", []): print(f"URL: {chunk.get('uri')}") print(f"Content: {chunk.get('content')[:200]}...")
results = client.search("Cloud Storage buckets") for chunk in results.get("documentChunks", []): print(f"URL: {chunk.get('uri')}") print(f"内容: {chunk.get('content')[:200]}...")

Get full document

获取完整文档

doc = client.get_document(chunk["parent"]) print(doc.get("content"))
undefined
doc = client.get_document(chunk["parent"]) print(doc.get("content"))
undefined

Explicit Authentication

显式身份验证

python
undefined
python
undefined

Using service account

使用服务账号

client = DeveloperKnowledgeClient(service_account_file="/path/to/sa.json")
client = DeveloperKnowledgeClient(service_account_file="/path/to/sa.json")

Using explicit access token

使用显式访问令牌

client = DeveloperKnowledgeClient(access_token="ya29.xxxx")
undefined
client = DeveloperKnowledgeClient(access_token="ya29.xxxx")
undefined

Convenience Method

便捷方法

python
undefined
python
undefined

Search and fetch full documents in one call

一次调用完成搜索并获取完整文档

docs = client.search_and_get("Firebase authentication", max_results=3) for doc in docs: print(doc["content"])
undefined
docs = client.search_and_get("Firebase authentication", max_results=3) for doc in docs: print(doc["content"])
undefined

cURL Examples

cURL示例

Get Access Token

获取访问令牌

bash
export TOKEN=$(gcloud auth application-default print-access-token)
bash
export TOKEN=$(gcloud auth application-default print-access-token)

Search

搜索

bash
curl -H "Authorization: Bearer $TOKEN" \
  "https://developerknowledge.googleapis.com/v1alpha/documents:searchDocumentChunks?query=BigQuery"
bash
curl -H "Authorization: Bearer $TOKEN" \
  "https://developerknowledge.googleapis.com/v1alpha/documents:searchDocumentChunks?query=BigQuery"

Get Document

获取文档

bash
curl -H "Authorization: Bearer $TOKEN" \
  "https://developerknowledge.googleapis.com/v1alpha/documents/developers.google.com/path/to/doc"
bash
curl -H "Authorization: Bearer $TOKEN" \
  "https://developerknowledge.googleapis.com/v1alpha/documents/developers.google.com/path/to/doc"

Covered Documentation

覆盖的文档范围

The API indexes these Google developer sites:
  • developer.android.com (Android)
  • firebase.google.com (Firebase)
  • docs.cloud.google.com (Google Cloud)
  • ai.google.dev (Gemini API / Google AI)
  • developers.google.com (Ads, Maps, YouTube, etc.)
  • developer.chrome.com (Chrome)
  • developers.home.google.com (Google Home)
  • www.tensorflow.org (TensorFlow)
  • web.dev (Web)
  • fuchsia.dev (Fuchsia)
该API已索引以下谷歌开发者站点:
  • developer.android.com(Android)
  • firebase.google.com(Firebase)
  • docs.cloud.google.com(Google Cloud)
  • ai.google.dev(Gemini API / Google AI)
  • developers.google.com(Ads、Maps、YouTube等)
  • developer.chrome.com(Chrome)
  • developers.home.google.com(Google Home)
  • www.tensorflow.org(TensorFlow)
  • web.dev(Web)
  • fuchsia.dev(Fuchsia)

Limitations

限制

  • Authentication: Requires OAuth2 (API keys do NOT work despite documentation)
  • Markdown Quality: Generated from HTML, may have formatting issues
  • Content Scope: Only public documentation pages, no GitHub/OSS/blogs/YouTube
  • Data Freshness: Re-indexed within 24 hours of publication
  • 身份验证:需要OAuth2(尽管文档说明API密钥可用,但实际不可用)
  • Markdown质量:由HTML生成,可能存在格式问题
  • 内容范围:仅包含公开文档页面,不包含GitHub/开源项目/博客/YouTube内容
  • 数据新鲜度:发布后24小时内完成重新索引

When to Use This Instead of MCP

何时替代MCP使用此API

Use direct API calls when:
  • MCP authentication is failing or not configured
  • You need more control over request/response handling
  • You're integrating into a pipeline that doesn't support MCP
  • You want to use the API in a standalone script
  • You need to handle OAuth2 tokens explicitly
在以下场景中使用直接API调用:
  • MCP身份验证失败或未配置
  • 你需要对请求/响应处理有更多控制权
  • 你要集成到不支持MCP的流水线中
  • 你希望在独立脚本中使用该API
  • 你需要显式处理OAuth2令牌

Official Documentation

官方文档