简体   繁体   English

无法设置 dialogFlow API

[英]Unable to set up dialogFlow API

I am trying to use this quick guide to set up dialogFlow API on my laravel project - https://cloud.google.com/dialogflow/docs/quick/api .我正在尝试使用此快速指南在我的 Laravel 项目上设置 dialogFlow API - https://cloud.google.com/dialogflow/docs/quick/api

This is the method I have created to detect intents, etc.这是我创建的用于检测意图等的方法。

function detect_intent_texts($projectId, $texts, $sessionId, $languageCode = 'en-US'){
        // new session
        $filePath = base_path('dialogflow.json');

        putenv("GOOGLE_APPLICATION_CREDENTIALS=".$filePath);

        $sessionsClient = new SessionsClient();

        $session = $sessionsClient->sessionName($projectId, $sessionId ?: uniqid());
        printf('Session path: %s' . PHP_EOL, $session);

        // query for each string in array
        foreach ($texts as $text) {
            // create text input
            $textInput = new TextInput();
            $textInput->setText($text);
            $textInput->setLanguageCode($languageCode);

            // create query input
            $queryInput = new QueryInput();
            $queryInput->setText($textInput);

            // get response and relevant info
            //dd($queryInput);
            $response = $sessionsClient->detectIntent($session, $queryInput);
            $queryResult = $response->getQueryResult();
            $queryText = $queryResult->getQueryText();
            $intent = $queryResult->getIntent();
            $displayName = $intent->getDisplayName();
            $confidence = $queryResult->getIntentDetectionConfidence();
            $fulfilmentText = $queryResult->getFulfillmentText();

            // output relevant info
            print(str_repeat("=", 20) . PHP_EOL);
            printf('Query text: %s' . PHP_EOL, $queryText);
            printf('Detected intent: %s (confidence: %f)' . PHP_EOL, $displayName,
                $confidence);
            print(PHP_EOL);
            printf('Fulfilment text: %s' . PHP_EOL, $fulfilmentText);
        }

        $sessionsClient->close();
    }

When I try to run the function using this -当我尝试使用此功能运行该功能时 -

$array = ['hello'];
 detect_intent_texts(env('DIALOGFLOW_PROJECT_ID'), $array, '134253474848');

I get this error-我收到此错误-

{ "message": "IAM permission 'dialogflow.sessions.detectIntent' on 'projects\/********\/agent' denied.", "code": 7, "status": "PERMISSION_DENIED", "details": [] }

Please what might be the problem here?请问这里可能是什么问题?

It sounds like you have not properly setup roles when configuring your service account.听起来您在配置服务帐户时没有正确设置角色。 See the auth setup steps .请参阅身份验证设置步骤

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

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