当将Dialogflow与Python结合使用时,它说即使我在终端中将其设置为过程,也无法确定我的凭据

时间:2018-08-29 16:22:42

标签: python dialogflow

import dialogflow

def explicit():
    from google.cloud import storage

    # Explicitly use service account credentials by specifying the private key
    # file.
    storage_client = storage.Client.from_service_account_json("MyJSON path")
    print("Hello World")
    # Make an authenticated API request
    print(buckets)

def detect_intent_texts(project_id, session_id, texts, language_code):
    """Returns the result of detect intent with texts as inputs.

    Using the same `session_id` between requests allows continuation
    of the conversaion."""
    #import dialogflow_v2 as dialogflow
    session_client = dialogflow.SessionsClient()
    session = session_client.session_path(project_id, session_id)
    #print('Session path: {}\n'.format(session))
    for text in texts:
        text_input = dialogflow.types.TextInput(
            text=text, language_code=language_code)

        query_input = dialogflow.types.QueryInput(text=text_input)

        response = session_client.detect_intent(
        session=session, query_input=query_input)

        print('=' * 20)
        print('Query text: {}'.format(response.query_result.query_text))
        print('Detected intent: {} (confidence: {})\n'.format(
        response.query_result.intent.display_name,
        response.query_result.intent_detection_confidence))
        print('Fulfillment text: {}\n'.format(
        response.query_result.fulfillment_text))


if __name__ == '__main__':
    exp=explicit()
    callfunction=detect_intent_texts("MyProjectID",1,"Hi","en-US")

当我运行以下代码(替换路径和项目ID)时,即使打印出存储区,我也会收到以下错误消息:

  

DefaultCredentialsError:无法自动确定   证书。请设置GOOGLE_APPLICATION_CREDENTIALS或明确设置   创建凭据并重新运行该应用程序。了解更多信息,   请参阅   https://developers.google.com/accounts/docs/application-default-credentials

有人可以帮忙吗?这里是新手。

谢谢!

0 个答案:

没有答案