通过 Cloud Endpoints 进行 Cloud Firestore REST API 调用?
是否可以创建 Cloud Endpoint 以便对 Firestore REST API 服务进行 HTTP 调用?
原因是使用自定义 URL 进行调用 - 例如“https://whatever.com/api/things”,而不是“https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(默认) )/文件/东西”。
我尝试为此创建一个 Open API yaml 文件,但收到错误:
用户无权访问服务实例 [firestore.googleapis.com](或者它可能不存在):调用者没有权限“servicemanagement”服务“firestore.googleapis.com”上的“.services.update”。
这是否可能,或者我是否必须创建一个云函数来实现此目的?
更新
这是我的yaml
文件:
swagger: '2.0'
info:
title: "My API"
description: "Returns something"
version: 1.0.0
host: "firestore.googleapis.com"
basePath: "v1/projects/app-emojise-com/databases/(default)/documents"
schemes:
- "https"
produces:
- application/json
paths:
"/foo/{fooId}":
get:
summary: "Returns foo"
operationId: "foo"
parameters:
-
name: fooId
in: path
required: true
type: string
responses:
200:
description: "OK"
type: string
404:
description: "Error"
type: string
403:
description: "Forbidden"
type: string
我尝试按照给定的示例此处
Is it possible to create a Cloud Endpoint in order to make HTTP calls to the Firestore REST API service?
The reason being to use a custom URL for the call - e.g. "https://whatever.com/api/things", instead of "https://firestore.googleapis.com/v1/projects/YOUR_PROJECT_ID/databases/(default)/documents/things".
I tried creating an Open API yaml file for this, but got an error:
User does not have permission to access services instance [firestore.googleapis.com] (or it may not exist): Caller does not have permission 'servicemanagement.services.update' on service 'firestore.googleapis.com'.
Is it even possible, or would I have to create a Cloud Function to achieve this instead?
UPDATE
Here is my yaml
file:
swagger: '2.0'
info:
title: "My API"
description: "Returns something"
version: 1.0.0
host: "firestore.googleapis.com"
basePath: "v1/projects/app-emojise-com/databases/(default)/documents"
schemes:
- "https"
produces:
- application/json
paths:
"/foo/{fooId}":
get:
summary: "Returns foo"
operationId: "foo"
parameters:
-
name: fooId
in: path
required: true
type: string
responses:
200:
description: "OK"
type: string
404:
description: "Error"
type: string
403:
description: "Forbidden"
type: string
I've tried following the example given here
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您看到的错误是因为您尝试将配置上传到不属于您的
firestore.googleapis.com
。这是在yaml
文件的“host”字段中指定的。相反,您必须使用自己的不同域名。Endpoints 是一个 API“控制平面”,它实际上并不处理代理请求。您正在执行的操作只会将 API 配置上传到我们的服务器。您将需要实际设置某种服务来侦听请求并将其转发到 Firestore 本身。我们确实提供了一个开源解决方案来执行此操作,称为 ESP ,但这仍然需要托管在某个地方。
理论上,Endpoints 旨在保护您自己的 API,而不是作为其他人的代理运行。结果,它很可能不会按您想要的方式工作。
我建议构建一个合适的 API,并将其托管在 Cloud Run 等内容上。您可能仍然想将端点与它一起使用。
The error you're seeing is because you're trying to upload a configuration to
firestore.googleapis.com
, which you do not own. This is specified in youryaml
file in the "host" field. Instead, you must use a different domain name of your own.Endpoints is an API "control plane", it doesn't actually handle proxying requests. The operation the you're performing will only upload an API configuration to our server. You will need to actually set up some kind of service to listen for requests and forward them on to Firestore itself. We do provide an open source solution to do this, called the ESP, but this still needs to be hosted somewhere.
In theory, Endpoints is designed to protect your own API, not run as a proxy to someone else's. As a result, It's likely that it won't work the way you want.
I'd suggest to just build a proper API, and host this on something like Cloud Run. You might still want to use Endpoints with it.