简体   繁体   English

Dialogflow V2 API

[英]Dialogflow V2 API

Dialogflow V2 API relies on Google Auth, is it possible to use Dialogflow V2 API without install anything (SDK, composer or anything) into the server? Dialogflow V2 API 依赖于 Google Auth,是否可以使用 Dialogflow V2 API 而无需在服务器中安装任何东西(SDK、composer 或任何东西)? I must to just use PHP\\JS as usual, this is mandatory due the integration will be for a commercial plugin used by WordPress users, of course the users will never install anything to the server and anyway it's not possible to install anything on common web hostings.我必须像往常一样使用 PHP\\JS,这是强制性的,因为集成将用于 WordPress 用户使用的商业插件,当然用户永远不会在服务器上安装任何东西,无论如何也不可能在公共网络上安装任何东西托管。 Thank you!谢谢!

You don't need to install anything to use Dialogflow.您无需安装任何东西即可使用 Dialogflow。

You just need to export Service Account Key (JSON) file, and set an environment variable GOOGLE_APPLICATION_CREDENTIALS to the file path of the JSON file that contains your service account key.您只需要导出服务帐户密钥 (JSON) 文件,并将环境变量GOOGLE_APPLICATION_CREDENTIALS设置为包含您的服务帐户密钥的 JSON 文件的文件路径。 Then you can make call to dialogflow.然后你可以调用dialogflow。

UPDATE :更新 :
Make sure you are using Dialogflow v2.确保您使用的是 Dialogflow v2。
Go to general settings and click on your Service Account.转到常规设置并单击您的服务帐户。 This will redirect you to Google Cloud Platform project's service account page.这会将您重定向到 Google Cloud Platform 项目的服务帐户页面。
Next step is to create a new key for the service account.下一步是为服务帐户创建一个新密钥。 Now create a service account and choose JSON as output key.现在创建一个服务帐户并选择 JSON 作为输出键。 Follow the instructions and a JSON file will be downloaded to your computer.按照说明操作,一个 JSON 文件将下载到您的计算机。 This file will be used as GOOGLE_APPLICATION_CREDENTIALS .此文件将用作GOOGLE_APPLICATION_CREDENTIALS

Now in code,现在在代码中,

import os
import dialogflow
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "/path/to/file.json"
project_id = "your_project_id"
session_id = "your_session_id"
language_code = "en"
session_client = dialogflow.SessionsClient()
session = session_client.session_path(project_id, session_id)

text_input = dialogflow.types.TextInput(text=text, language_code=language_code)
query_input = dialogflow.types.QueryInput(text=text_input)
response_dialogflow = session_client.detect_intent(session=session, query_input=query_input)

Hope it helps.希望能帮助到你。

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

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