2

I recently updated from version 1 of the AWS SDK for PHP to version 3 of the AWS SDK so that I could start testing scripts using the Comprehend and Textract applications. I was able to connect through version 3 and utilize S3 using the "new S3Client()" command. There's extensive documentation regarding functions for Comprehend and Textract, but I can't figure out what the similar new client string is for each service. I've tried:
$cc = new comprehendClient();
$cc = new AWSComprehend();
$cc = new createComprehend();
and more and none of these have worked. If anyone can recommend a fix that would be really helpful. Likewise, if there's an online code repository I should look at that would be helpful. I see plenty of code samples for S3, but none for other applications (at least with SDK for PHP). Thanks!

John Rotenstein
  • 241,921
  • 22
  • 380
  • 470
user1120540
  • 121
  • 1
  • 8

1 Answers1

4

From the AWS Comprehend PHP documentation provided, a Comprehend client can be instantiated and called like below :

require 'vendor/autoload.php';

use Aws\Exception\AwsException;
use Aws\Comprehend\ComprehendClient;

/**
 * This code expects that you have AWS credentials set up per:
 * https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html
 */


$ComprehendClient = \Aws\Comprehend\ComprehendClient::factory(array(
    'credentials' => [
        'key'    => 'AKIAXXXXXX',
        'secret' => '+TsIDxxxxxxx',
    ],
    'region' => 'us-east-1',
    'version'  => 'latest',
));

$result = $ComprehendClient->detectDominantLanguage([
    'Text' => "Nakabibili pala ng durian sa U.S. supermarkets kasama ng mga epol. Galing siguro sa Thailand.", // REQUIRED
]);


echo $result;
aksyuma
  • 2,957
  • 1
  • 15
  • 29
  • Thanks for this. I figured it out over the weekend. The key was using quotes (") instead of single slashes (') around the access key and secret code. Kind of amazing that this slight change made a world of difference, but it did! – user1120540 Sep 03 '19 at 23:50
  • @user1120540, using either single quotes (') or double quotes (") still works. You can accept my answer if it helped you solve your question. – aksyuma Sep 05 '19 at 04:07