无法设置dialogFlow API

问题描述 投票:0回答:1

我正在尝试使用此快速指南在laravel项目-https://cloud.google.com/dialogflow/docs/quick/api上设置dialogFlow API。

这是我创建的用于检测意图等的方法。

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();
    }

[当我尝试使用此功能运行功能时-

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

我收到此错误-

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

请问这里可能是什么问题?

php laravel dialogflow
1个回答
0
投票

听起来您在配置服务帐户时似乎没有正确设置角色。参见auth setup steps

© www.soinside.com 2019 - 2024. All rights reserved.