什么是 Google API 发现?

What is Google API Discovery?

我无法理解 Google products/services 中使用的“API 发现”的概念。这里有一些 Python 代码使用上述发现服务访问 Google Cloud Vision:

from googleapiclient.discovery import build
from oauth2client.client import GoogleCredentials
… 
API_DISCOVERY_FILE = 'https://vision.googleapis.com/$discovery/rest?version=v1'
hlh = httplib2.Http()
credentials = GoogleCredentials.get_application_default().create_scoped(
    ['https://www.googleapis.com/auth/cloud-platform'])
credentials.authorize(hlh)
service = build(serviceName='vision', version='v1', http=hlh, discoveryServiceUrl=API_DISCOVERY_FILE)
service_request = service.images().annotate(body={ <more JSON code here> })

这是另一段 Python 代码,它也可以访问 Google Cloud Vision,但不使用 API 发现 并且工作正常 :

import requests
…
ENDPOINT_URL = 'https://vision.googleapis.com/v1/images:annotate'
response = requests.post(ENDPOINT_URL,
    data=make_image_data(image_filenames),
    params={'key': api_key},
    headers={'Content-Type': 'application/json'})

我想不通的是这个问题:您需要知道您将要呼叫的 API 的详细信息,以便您可以定制呼叫;这是显而易见的。那么,在您已经准备好调用该 API 的代码之后,API 发现在调用时如何帮助您?

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

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

You need to know the details of the API that you are going to be calling so that you can tailor the call; this is obvious.

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

实际上,一旦您拥有大量资源并且它们之间存在各种相互关系,这就很难做到。