简体   繁体   中英

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 .

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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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