gpt4 book ai didi

python-3.x - 使用 Python 连接 Dialogflow V2 api

转载 作者:行者123 更新时间:2023-12-04 02:08:23 29 4
gpt4 key购买 nike

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

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

做完这一切,当我跑

from google.cloud import storage
storage_client = storage.Client()
buckets = list(storage_client.list_buckets())
print(buckets)

它给了我错误,
OSError: Project was not passed and could not be determined from the environment.

因此,我在存储客户端本身中设置了项目名称。
storage_client = storage.Client(project='[Project-id]')

所以,这解决了代码的问题,不过,我认为它应该自己检测到项目 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()

在此之后,我收到以下错误,
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.

任何帮助,将不胜感激。

最佳答案

请设置环境变量GOOGLE_APPLICATION_CREDENTIALS https://cloud.google.com/dialogflow-enterprise/docs/reference/libraries

示例:

export GOOGLE_APPLICATION_CREDENTIALS="/home/thanhha/owner-project-ab.json"

关于python-3.x - 使用 Python 连接 Dialogflow V2 api,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48145572/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com