使用Python连接Dialogflow V2 API

Apu*_*and 6 python-3.x api-ai dialogflow-es

如文档中所述,我已经设置了云帐户并激活了dialogflow API。然后,我在我的dialogflow.com帐户中激活了dialogflow V2,并在其中设置了相同的google项目。

我以JSON格式下载了Google凭据,并相应地设置了身份验证的路径。

完成所有这些之后,当我跑步时

from google.cloud import storage
storage_client = storage.Client()
buckets = list(storage_client.list_buckets())
print(buckets)
Run Code Online (Sandbox Code Playgroud)

它给了我错误,

OSError: Project was not passed and could not be determined from the environment.
Run Code Online (Sandbox Code Playgroud)

因此,我在存储客户端本身中设置了项目名称。

storage_client = storage.Client(project='[Project-id]')
Run Code Online (Sandbox Code Playgroud)

因此,这仍然解决了代码问题,我认为它应该自己检测出project-id,而不必像文档中所提供的那样提供项目ID。

完成所有这些之后,我尝试运行以下程序以检查连接,

import dialogflow_v2beta1
client = dialogflow_v2beta1.AgentsClient()
parent = client.project_path('[Project-id]')
response = client.import_agent(parent)

def callback(operation_future):
    result = operation_future.result()

response.add_done_callback(callback)
metadata = response.metadata()
Run Code Online (Sandbox Code Playgroud)

此后,我收到以下错误消息,

PermissionDenied: 403 Dialogflow API has not been used in project usable-auth-library before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/dialogflow.googleapis.com/overview?project=usable-auth-library then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激。

Tel*_*lmo 0

您是否遵循此操作: https ://dialogflow.com/docs/reference/v2-auth-setup

我遇到了同样的错误,但这解决了它。您只需要设置身份验证即可。有什么问题就问我吧。

  • 您能详细告诉我您做了什么吗? (2认同)