6

如文档中所述,我已经设置了云帐户并激活了对话流 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)

它给了我错误,

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.

任何帮助,将不胜感激。

4

3 回答 3

1

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

例子:

export GOOGLE_APPLICATION_CREDENTIALS="/home/thanhha/owner-project-ab.json"
于 2018-04-26T06:44:57.017 回答
1

一旦我们按照https://dialogflow.com/docs/reference/v2-auth-setup?authuser=2中的说明创建服务帐户密钥(这是一个 json 文件,让我们将其重命名为private_key.json

正如@ThanhHa所提到的,我们需要在环境变量中设置它。通过终端设置环境变量的另一种方法是将以下代码添加到您的 python 代码中。

import os
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = 'private_key.json'

这解决了我的问题。

于 2019-09-19T22:36:36.373 回答
0

Have you followed this: https://dialogflow.com/docs/reference/v2-auth-setup

I was getting the same error, but this fixed it. You just need to set up the authentication. Any questions ask me.

于 2018-03-22T11:44:56.153 回答