php 初始化Google RecaptchaEnterpriseServiceClient时出错

ezykj2lf  于 2023-06-28  发布在  PHP
关注(0)|答案(1)|浏览(163)

我正在尝试将reCAPCHA添加到我的网站。在README.mdhttps://github.com/googleapis/google-cloud-php-recaptcha-enterprise的www.example.com之后,我使用composer在我的服务器上安装了google/cloud-recaptcha-enterprise:

cd includes
composer require google/cloud-recaptcha-enterprise
cd ..

然后创建一个简单的test.php

<?php

error_reporting(E_ALL);

require 'includes/vendor/autoload.php';

use Google\Cloud\RecaptchaEnterprise\V1\Key;
use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient;
use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings;
use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings\IntegrationType;

$client = new RecaptchaEnterpriseServiceClient();

echo "DONE";
?>

但我得到一个“HTTP ERROR 500”页面不工作。没有警告,没有错误报告。我已经看过autoloader.php,它生成的路径是正确的。我已经检查了一些其他的软件包,我已经安装在我的包括/目录和自动加载器工程罚款与这些。
我试过composer 2 +PHP8.2和composer 1 +PHP7.4。
我已经尝试不安装到我的包含文件夹。
为了调试一下自动加载器,我修改了test.php:

<?php

error_reporting(E_ALL);

$autoloader = require 'includes/vendor/autoload.php';
print_r($autoloader);
echo "</br></br>";
$results = $autoloader->findFile("Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient");
print "Found file for class at: $results</br></br>";

echo $autoloader->loadClass("Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient");

use Google\Cloud\RecaptchaEnterprise\V1\Key;
use Google\Cloud\RecaptchaEnterprise\V1\RecaptchaEnterpriseServiceClient;
use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings;
use Google\Cloud\RecaptchaEnterprise\V1\WebKeySettings\IntegrationType;

$client =  new RecaptchaEnterpriseServiceClient();

echo "DONE";
?>

我得到以下输出:

Composer\Autoload\ClassLoader Object ( [vendorDir:Composer\Autoload\ClassLoader:private] => /home/<user>/domains/<domain>/public_html/includes/vendor [prefixLengthsPsr4:Composer\Autoload\ClassLoader:private] => Array ( [P] => Array ( [Psr\Http\Message\] => 17 [Psr\Http\Client\] => 16 [Psr\Cache\] => 10 [PHPMailer\PHPMailer\] => 20 ) [G] => Array ( [GuzzleHttp\Psr7\] => 16 [GuzzleHttp\Promise\] => 19 [GuzzleHttp\] => 11 [Grpc\Gcp\] => 9 [Grpc\] => 5 [Google\Type\] => 12 [Google\Rpc\] => 11 [Google\Protobuf\] => 16 [Google\LongRunning\] => 19 [Google\Iam\] => 11 [Google\Cloud\RecaptchaEnterprise\] => 33 [Google\Cloud\] => 13 [Google\Auth\] => 12 [Google\Api\] => 11 [Google\ApiCore\LongRunning\] => 27 [Google\ApiCore\] => 15 [GPBMetadata\Google\Type\] => 24 [GPBMetadata\Google\Rpc\] => 23 [GPBMetadata\Google\Protobuf\] => 28 [GPBMetadata\Google\Longrunning\] => 31 [GPBMetadata\Google\Logging\] => 27 [GPBMetadata\Google\Iam\] => 23 [GPBMetadata\Google\Cloud\Recaptchaenterprise\] => 45 [GPBMetadata\Google\Cloud\] => 25 [GPBMetadata\Google\Api\] => 23 [GPBMetadata\ApiCore\] => 20 ) [F] => Array ( [Firebase\JWT\] => 13 ) ) [prefixDirsPsr4:Composer\Autoload\ClassLoader:private] => Array ( [Psr\Http\Message\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../psr/http-message/src [1] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../psr/http-factory/src ) [Psr\Http\Client\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../psr/http-client/src ) [Psr\Cache\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../psr/cache/src ) [PHPMailer\PHPMailer\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../PHPMailer ) [GuzzleHttp\Psr7\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../guzzlehttp/psr7/src ) [GuzzleHttp\Promise\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../guzzlehttp/promises/src ) [GuzzleHttp\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../guzzlehttp/guzzle/src ) [Grpc\Gcp\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src ) [Grpc\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../grpc/grpc/src/lib ) [Google\Type\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/src/Type ) [Google\Rpc\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/src/Rpc ) [Google\Protobuf\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/protobuf/src/Google/Protobuf ) [Google\LongRunning\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/longrunning/src/LongRunning ) [Google\Iam\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/src/Iam ) [Google\Cloud\RecaptchaEnterprise\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/cloud-recaptcha-enterprise/src ) [Google\Cloud\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/src/Cloud ) [Google\Auth\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/auth/src ) [Google\Api\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/src/Api ) [Google\ApiCore\LongRunning\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/longrunning/src/ApiCore/LongRunning ) [Google\ApiCore\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/gax/src ) [GPBMetadata\Google\Type\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Type ) [GPBMetadata\Google\Rpc\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Rpc ) [GPBMetadata\Google\Protobuf\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/protobuf/src/GPBMetadata/Google/Protobuf ) [GPBMetadata\Google\Longrunning\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/longrunning/metadata/Longrunning ) [GPBMetadata\Google\Logging\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Logging ) [GPBMetadata\Google\Iam\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Iam ) [GPBMetadata\Google\Cloud\Recaptchaenterprise\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/cloud-recaptcha-enterprise/metadata ) [GPBMetadata\Google\Cloud\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Cloud ) [GPBMetadata\Google\Api\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/common-protos/metadata/Api ) [GPBMetadata\ApiCore\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/gax/metadata/ApiCore ) [Firebase\JWT\] => Array ( [0] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../firebase/php-jwt/src ) ) [fallbackDirsPsr4:Composer\Autoload\ClassLoader:private] => Array ( ) [prefixesPsr0:Composer\Autoload\ClassLoader:private] => Array ( ) [fallbackDirsPsr0:Composer\Autoload\ClassLoader:private] => Array ( ) [useIncludePath:Composer\Autoload\ClassLoader:private] => [classMap:Composer\Autoload\ClassLoader:private] => Array ( [Composer\InstalledVersions] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../composer/InstalledVersions.php [GPBMetadata\GrpcGcp] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/GPBMetadata/GrpcGcp.php [Grpc\Gcp\AffinityConfig] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/Grpc/Gcp/AffinityConfig.php [Grpc\Gcp\AffinityConfig_Command] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/Grpc/Gcp/AffinityConfig_Command.php [Grpc\Gcp\ApiConfig] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/Grpc/Gcp/ApiConfig.php [Grpc\Gcp\ChannelPoolConfig] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/Grpc/Gcp/ChannelPoolConfig.php [Grpc\Gcp\MethodConfig] => /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/grpc-gcp/src/generated/Grpc/Gcp/MethodConfig.php ) [classMapAuthoritative:Composer\Autoload\ClassLoader:private] => [missingClasses:Composer\Autoload\ClassLoader:private] => Array ( ) [apcuPrefix:Composer\Autoload\ClassLoader:private] => )

Found file for class at: /home/<user>/domains/<domain>/public_html/includes/vendor/composer/../google/cloud-recaptcha-enterprise/src/V1/RecaptchaEnterpriseServiceClient.php

1

所以自动加载器正在查找文件,但名称空间不正确?脚本仍然没有完成“DONE”步骤,类也没有创建。
任何帮助都将不胜感激

r1zk6ea1

r1zk6ea11#

我不知道为什么我的脚本没有显示抛出的异常,但是通过将echos放入google类中进行调试,我发现了这个异常:

Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc

所以,创建一个凭证密钥文件并设置一个环境变量GOOGLE_APPLICATION_CREDENTIAL解决了当前的问题。

相关问题