什么是 Google API 发现? [英] What is Google API Discovery?

查看:32
本文介绍了什么是 Google API 发现?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法理解 Google 产品/服务中使用的API 发现"概念.下面是一些使用上述发现服务访问 Google Cloud Vision 的 Python 代码:

I am having trouble understanding the concept of "API discovery" as used in Google products/services. Here’s some Python code that uses the said discovery service to access 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 发现并且工作正常:

Here’s another bit of Python code that also accesses Google Cloud Vision, but does not use API discovery and works just fine:

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 发现在调用时对您有何帮助??

What I can’t wrap my head around is this question: 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. So, how would API discovery help you at the time of the call, after you have already prepared the code for calling that API?

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

PS: I did look at the following resources prior to posting this question:
https://developers.google.com/discovery/v1/getting_started
https://developers.google.com/discovery/v1/using
I did see this answered question but would appreciate additional insight.

推荐答案

注意:我缺乏您提到的 Google API 的知识.

Note: I lack the knowledge of the Google API you are mentioning.

您需要了解您将要使用的 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 以通用方式浏览这种可发现性,那么人们将能够决定要做什么.

In theory to me this is only required for the very first call, which would be the call to a starting service which would for instance list a number of resources. From there on you can have branches to underlying resources and their allowed methods (verbs if you will). So this example illustrated a tree like structure. If you provide a GUI to navigate through this discoverability in a generic way, a person would then be able to decide what to do.

实际上,一旦您拥有大量资源以及它们之间的各种相互关系,就很难做到这一点.

In practice this is kind of hard to do once you have vast amounts of resources and all sorts of interrelationships between them.

这篇关于什么是 Google API 发现?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆