前提条件
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在开始编写您的首个客户端应用之前,您需要做一些准备工作(如果您还没有做的话)。
获取 Google 账号
您需要拥有一个 Google 账号才能在 Google API 控制台中创建项目。如果您已经具有账号,则您已准备就绪。
您可能还需要一个用来测试的单独 Google 账号。
为客户端创建一个项目
在向 Google Knowledge Graph Search API 发送请求之前,您需要告知 Google 您的客户端并激活对 API 的访问权限。为此,您可以使用 Google API 控制台创建一个项目(该项目是设置和 API 访问信息的命名集合),然后注册您的应用。
要开始使用 Google Knowledge Graph Search API,您需要先使用设置工具,该工具会引导您在 Google API 控制台中创建项目、启用 API 以及创建凭据。
如果您尚未创建应用的 API 密钥,请依次点击创建凭据 > API 密钥进行创建。接下来,在 API 密钥部分中查找您的 API 密钥。
了解 REST 基础知识
您可以通过以下两种方式调用 API:
如果您决定不使用客户端库,则将需要了解 REST 的基础知识。
REST 是一种软件架构样式,可提供便利、一致的方法来请求和修改数据。
术语 REST 是“具象状态传输”的简称。在 Google API 的上下文中,指的是使用 HTTP 谓词来检索和修改由 Google 存储的数据的表示法。
在 RESTful 系统中,资源存储在数据存储区中;在客户端发送要求服务器执行特定操作(例如创建、检索、更新或删除资源)的请求之后,服务器便会执行该操作并发送响应,此响应的格式通常为所指定资源的表示法。
在 Google 的 RESTful API 中,客户端使用 HTTP 谓词(例如 POST
、GET
、PUT
或 DELETE
)指定操作。它通过以下格式的全局唯一 URI 来指定资源:
https://www.googleapis.com/apiName/apiVersion/resourcePath?parameters
由于所有 API 资源都具有 HTTP 可访问的唯一 URI,因此 REST 启用了数据缓存,而且经过优化以与网络的分布式基础架构一起使用。
您可能会发现 HTTP 1.1 标准文档中的方法定义十分有用;这些定义中包含了 GET
、POST
、PUT
和 DELETE
的规范。
Google Knowledge Graph Search API 中的 REST
Google Knowledge Graph Search API 操作会直接映射到 REST HTTP 动词。
Google Knowledge Graph Search API URI 的具体格式如下:
https://kgsearch.googleapis.com/v1/entities:search?query=your_query¶meters
Google Knowledge Graph Search API 参考文档总结了用于 API 中各项受支持操作的全套 URI。
了解 JSON 基础知识
Google Knowledge Graph Search API 以 JSON 格式返回数据。
JSON(JavaScript 对象表示法)是一种与语言无关的常见数据格式,可通过简单的文本来表示任意数据结构。如需了解详情,请参阅 json.org。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-31。
[null,null,["最后更新时间 (UTC):2025-08-31。"],[[["\u003cp\u003eBefore coding, ensure you have a Google Account and have created a project in the Google API Console to manage settings and API access.\u003c/p\u003e\n"],["\u003cp\u003eUnderstand REST basics, focusing on using HTTP verbs to retrieve and modify data, which the Google Knowledge Graph Search API utilizes.\u003c/p\u003e\n"],["\u003cp\u003eFamiliarize yourself with JSON, the data format used by the Google Knowledge Graph Search API for returning information.\u003c/p\u003e\n"],["\u003cp\u003eTo use the API without client libraries, learn how to send HTTP requests, parse responses, and construct RESTful URIs to access and manipulate data.\u003c/p\u003e\n"]]],[],null,["Before you can start coding your first client application, there are a few\nthings you need to do, if you haven't done them already.\n1. [Get a Google Account](#getaccount)\n2. [Create a project for your client](#project)\n3. [Learn REST basics](#rest)\n4. [Learn JSON basics](#data-json)\n\nGet a Google Account\n\nYou need a [Google Account](https://www.google.com/accounts/NewAccount) in order to [create a project](#project) in the Google API Console. If you already have an account, then you're all set.\n\nYou may also want a separate Google Account for testing purposes.\n\nCreate a project for your client\n\nBefore you can send requests to Google Knowledge Graph Search API, you need to tell Google about your client and activate access to the API. You do this by using the Google API Console to create a project, which is a named collection of settings and API access information, and register your application.\n\nTo get started using Google Knowledge Graph Search API, you need to first\n[use\nthe setup tool](https://console.cloud.google.com/start/api?id=kgsearch.googleapis.com&credential=client_key), which guides you through creating a project in the\nGoogle API Console, enabling the API, and creating credentials.\n\nIf you haven't done so already, create your application's API key by clicking\n**Create credentials \\\u003e API key** . Next, look for your API key in the **API\nkeys** section.\n\nLearn REST basics\n\nThere are two ways to invoke the API:\n\n- Sending HTTP requests and parsing the responses.\n- Using [client libraries](/knowledge-graph/libraries).\n\nIf you decide not to use client libraries, you'll need to understand the basics of REST.\n\nREST is a style of software architecture that provides a convenient and consistent approach to requesting and modifying data.\n\nThe term REST is short for \"[Representational State Transfer](https://en.wikipedia.org/wiki/Representational_state_transfer).\" In the context of Google APIs, it refers to using HTTP verbs to retrieve and modify representations of data stored by Google.\n\nIn a RESTful system, resources are stored in a data store; a client sends a request that the server perform a particular action (such as creating, retrieving, updating, or deleting a resource), and the server performs the action and sends a response, often in the form of a representation of the specified resource.\n\nIn Google's RESTful APIs, the client specifies an action using an HTTP verb such as `POST`, `GET`, `PUT`, or `DELETE`. It specifies a resource by a globally-unique URI of the following form: \n\n```\nhttps://www.googleapis.com/apiName/apiVersion/resourcePath?parameters\n```\n\nBecause all API resources have unique HTTP-accessible URIs, REST enables data caching and is optimized to work with the web's distributed infrastructure.\n\nYou may find the [method definitions](https://tools.ietf.org/html/rfc7231#section-4.3) in the HTTP 1.1 standards documentation useful; they include specifications for `GET`, `POST`, `PUT`, and `DELETE`.\n\nREST in the Google Knowledge Graph Search API\n\nThe Google Knowledge Graph Search API operations map directly to REST HTTP verbs.\n\nThe specific formats for Google Knowledge Graph Search API URIs are: \n\n```\nhttps://kgsearch.googleapis.com/v1/entities:search?query=your_query¶meters\n```\n\nThe full set of URIs used for each supported operation in the API is summarized in the [Google Knowledge Graph Search API Reference](/knowledge-graph/reference/rest/v1) document.\n\nLearn JSON basics\n\nThe Google Knowledge Graph Search API returns data in JSON format.\n\n\n[JSON](http://en.wikipedia.org/wiki/JSON) (JavaScript Object Notation) is a common, language-independent data format that provides a simple text representation of arbitrary data structures. For more information, see [json.org](http://www.json.org/).\n\n\u003cbr /\u003e"]]