什么是 Google API 发现?

Sab*_*ncu 5 python rest google-api-discovery

我无法理解 Google 产品/服务中使用的 \xe2\x80\x9cAPI discovery\xe2\x80\x9d 的概念。这里\xe2\x80\x99是一些使用上述发现服务访问Google Cloud Vision的Python代码:

\n\n
from googleapiclient.discovery import build\nfrom oauth2client.client import GoogleCredentials\n\xe2\x80\xa6 \nAPI_DISCOVERY_FILE = \'https://vision.googleapis.com/$discovery/rest?version=v1\'\nhlh = httplib2.Http()\ncredentials = GoogleCredentials.get_application_default().create_scoped(\n    [\'https://www.googleapis.com/auth/cloud-platform\'])\ncredentials.authorize(hlh)\nservice = build(serviceName=\'vision\', version=\'v1\', http=hlh, discoveryServiceUrl=API_DISCOVERY_FILE)\nservice_request = service.images().annotate(body={ <more JSON code here> })\n
Run Code Online (Sandbox Code Playgroud)\n\n

Here\xe2\x80\x99s 的另一段 Python 代码也可以访问 Google Cloud Vision,但不使用 API 发现并且工作得很好

\n\n
import requests\n\xe2\x80\xa6\nENDPOINT_URL = \'https://vision.googleapis.com/v1/images:annotate\'\nresponse = requests.post(ENDPOINT_URL,\n    data=make_image_data(image_filenames),\n    params={\'key\': api_key},\n    headers={\'Content-Type\': \'application/json\'})\n
Run Code Online (Sandbox Code Playgroud)\n\n

我能\xe2\x80\x99t思考的是这个问题:你需要知道你将要调用的API的详细信息,以便你可以定制调用;这是显而易见的。那么,在您准备好调用该 API 的代码之后,API 发现将如何在调用时为您提供帮助

\n\n

PS:在发布此问题之前,我确实查看了以下资源:\n
\n https://developers.google.com/discovery/v1/getting_started \n
\n https://developers.google.com/discovery/ v1/using \n
\n我确实看到了这个已回答的问题,但希望有更多的见解。

\n

Kay*_*sar 2

注意:我缺乏你提到的 Google API 的知识。

您需要了解要调用的 API 的详细信息,以便可以定制调用;这是显而易见的。

从理论上讲,对我来说,这仅在第一次调用时需要,这将是对启动服务的调用,例如,该服务会列出许多资源。从那里开始,您可以分支到底层资源及其允许的方法(如果愿意,可以使用动词)。所以这个例子说明了一个树状结构。如果您提供一个 GUI 来以通用方式浏览这种可发现性,那么人们就能够决定要做什么。

在实践中,一旦你拥有大量资源以及它们之间的各种相互关系,这就很难做到。