简体   繁体   English

如何在没有 Cloud Functions 的情况下从 iOS (Swift) 向 Dialogflow V2 API 发送请求?

[英]How to send request from iOS (Swift) to Dialogflow V2 API without Cloud Functions?

Is it possible (and how) to call Dialogflow V2 API directly for intent detection from iOS app (Swift) or do I need to use Cloud Functions as suggested here Dialogflow integration of enterprise edition v2 into the ios and andriod app ?是否可以(以及如何)直接调用 Dialogflow V2 API 以从 iOS 应用程序 (Swift) 进行意图检测,或者我是否需要按照此处的建议使用 Cloud Functions 将企业版 v2 的 Dialogflow 集成到 ios 和 andriod 应用程序中

I have some experience in Dialogflow but all my integrations were done by FB Messenger / Web demo so I am totally lost in iOS case and I cannot find clear explanation in GCP / DF documentation.我在 Dialogflow 方面有一些经验,但我所有的集成都是通过 FB Messenger/Web 演示完成的,所以我完全迷失在 iOS 案例中,我在 GCP/DF 文档中找不到明确的解释。

While it is possible , it is not a good idea.虽然这是可能的,但这不是一个好主意。

In theory, you can call the Dialogflow Detect Intent API directly from your application using a REST interface.理论上,您可以使用 REST 接口直接从您的应用程序调用Dialogflow Detect Intent API

The problem is that, as part of this, you need to include authentication .问题是,作为其中的一部分,您需要包含authentication This authentication is based on a service account and the private key for that account.此身份验证基于服务帐户和该帐户的私钥。

So in order to send a request to your service, you need to include the private key in your app.因此,为了向您的服务发送请求,您需要在您的应用程序中包含私钥。 As you might guess - this is somewhat insecure.正如您可能猜到的 - 这有点不安全。 Which is why the SO question you link to suggests using a web service (it doesn't have to be on Cloud Functions - it can be anywhere) as the intermediary.这就是为什么您链接到的 SO 问题建议使用 Web 服务(它不必在 Cloud Functions 上 - 它可以在任何地方)作为中介。 You can put the private key in the service, where it can be more protected, and use some less secure method to communicate between your app and the service if you feel its necessary.您可以将私钥放在服务中,这样可以更好地保护它,并在您觉得有必要时使用一些不太安全的方法在您的应用程序和服务之间进行通信。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM