php - Paypal REST Api 错误 : response 401 PPConnectionException

标签 php rest oauth-2.0 paypal

我正在使用 PHP PayPal REST API 沙箱,在执行 $payment->create( $apiContext );

时出现错误

我的错误日志如下:

    PHP Fatal error:  Uncaught exception 'PayPal\\Exception\\PPConnectionException' with message 

'Got Http response code 401 when accessing https://api.paypal.com/v1/oauth2/token. 
    Retried 0 times.' in /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php:99\nStack trace:\n

#0 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Auth/OAuthTokenCredential.php(96): 
    PayPal\\Core\\PPHttpConnection->execute('grant_type=clie...')\n

#1 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Auth/OAuthTokenCredential.php(76): 
    PayPal\\Auth\\OAuthTokenCredential->_generateAccessToken(Array)\n

#2 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/Rest/RestHandler.php(56): PayPal\\Auth\\OAuthTokenCredential->getAccessToken(Array)\n

#3 /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Transport/PPRestCall.php(41): 
    PayPal\\Rest\\RestHandler->handle(Object(PayPal\\Core\\PPHttpConfig), '{"intent":"sale...', Array)\n

#4 /usr/local/web/servers/domain/guts/paypal_api/lib/PayPal/A in 
    /usr/local/web/servers/domain/guts/paypal_api/vendor/paypal/sdk-core-php/lib/PayPal/Core/PPHttpConnection.php on line 99, 
    referer: http://domain.com/products/basket/verify/

我的 PayPal.log 文件显示:

PayPal\Core\PPHttpConnection: Connecting to https://api.paypal.com/v1/oauth2/token
PayPal\Core\PPHttpConnection: Payload grant_type=client_credentials
PayPal\Core\PPHttpConnection: Adding header User-Agent: PayPalSDK/rest-sdk-php 0.6.0 (lang=PHP;v=5.3.3;bit=64;os=Linux_2.6.18-348.6.1.el5;machine=x86_64;openssl=0.9.8e-fips-rhel5;curl=7.15.5)
PayPal\Core\PPHttpConnection: Adding header Authorization: Basic QVpteVVCQ3VfdDhlb3QxcGx0UksyUG56Y3NhcXpOeXNIMlNDLXBDbTlUNGVGNDE3OFd1cFBFRmhkTVpnOkVGZ3g4UkNCZUppSkw3NW1JV1FDRFROTVVsanFOLW1fdlFuM3owMzZOZ3EwTUp3RVFwRkNlV0Z0dWhaag==
PayPal\Core\PPHttpConnection: Adding header Accept: */*

我试过测试抄送号码,在 Paypal 的沙盒网站上设置抄送号码。我已经尝试使用 rest-api-skd-php-master 中提供的演示应用程序中的凭据(顺便说一句,该演示有效)。

我可以向您展示我的代码,尽管它非常精确地模拟了测试用例。

我唯一能想到的是处理文件被埋在 www 访问级别之下?

如果您可以清除错误日志中的任何信息,我会洗耳恭听。如果您需要我提供更多信息,我可以提供。

最佳答案

如果您打算按照第一行中的说明使用沙箱,则会发生错误,因为您正在调用生产 PayPal 服务器。

改变 https://api.paypal.com/v1/oauth2/token

https://api.sandbox.paypal.com/v1/oauth2/token

关于php - Paypal REST Api 错误 : response 401 PPConnectionException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18023881/

相关文章:

php - php 代码中未处理 Html 搜索栏值

java - 休息API : How to make a `POST` call in `JSON` using Java?

wordpress - 验证 WordPress REST API JWT token 时出现 jwt_auth_no_auth_header 错误

hibernate - 是否可以停止 jpa 中的连接?

java - 为什么我不能自动连接 AuthorizationServerTokenServices 或 ConsumerTokenServices? "There is more than one bean of [this] type"

ruby-on-rails - ruby 的 oauth2 grant_type

java - This app isn't verified 此应用尚未经过 Google 验证。仅当您了解并信任开发人员时才继续

php - Laravel 将数据传递给 Controller

php - composer autoload.php 无法打开流 : no such file or directory

php - 比较值顺序不同的两个数组