Php PayPal API:访问时出现异常:401https://api.sandbox.paypal.com/v1/oauth2/token

Php PayPal API:访问时出现异常:401https://api.sandbox.paypal.com/v1/oauth2/token,php,paypal,oauth-2.0,Php,Paypal,Oauth 2.0,我得到的特定401错误消息是: “错误”:“客户端无效”,“错误描述”:“客户端凭据无效”}“ PayPal文档中没有列出此错误。我确信我正在使用测试凭据和正确的沙盒终结点。当我尝试获取访问令牌时,会发生此错误 这是检索访问令牌的类: private function _generateAccessToken($config) { $base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret)

我得到的特定
401
错误消息是:

“错误”:“客户端无效”,“错误描述”:“客户端凭据无效”}“

PayPal文档中没有列出此错误。我确信我正在使用测试凭据和正确的沙盒终结点。当我尝试获取访问令牌时,会发生此错误

这是检索访问令牌的类:

private function _generateAccessToken($config) {

$base64ClientID = base64_encode($this->clientId . ":" . $this->clientSecret);                           
$headers = array(
    "User-Agent" => PPUserAgent::getValue(RestHandler::$sdkName, RestHandler::$sdkVersion), 
    "Authorization" => "Basic " . $base64ClientID,
    "Accept" => "*/*"
);      
$httpConfiguration = $this->getOAuthHttpConfiguration($config); 
$httpConfiguration->setHeaders($headers); 

$connection = PPConnectionManager::getInstance()->getConnection($httpConfiguration, $config);
//print_r($connection); die;
$res = $connection->execute("grant_type=client_credentials");       

$jsonResponse = json_decode($res, true);
if($jsonResponse == NULL || 
        !isset($jsonResponse["access_token"]) || !isset($jsonResponse["expires_in"]) ) {
    $this->accessToken = NULL;
    $this->tokenExpiresIn = NULL;   
    $this->logger->warning("Could not generate new Access token. Invalid response from server: " . $jsonResponse);      
} else {
    $this->accessToken = $jsonResponse["access_token"];
    $this->tokenExpiresIn = $jsonResponse["expires_in"];
}
$this->tokenCreateTime = time();
return $this->accessToken;
}
这是我在打印时使用的
$connection
变量(我删除了授权字符串):


据我所知,我有正确的凭据、正确的端点,不确定它可能是什么?

如果无法识别客户端id/secret(环境的凭据错误,或者凭据未处于活动状态),则返回/token上的HTTP401

您能否通过cURL运行测试以排除任何环境/代码特定的问题

curl -v -u "client_id:secret" "https://api.sandbox.paypal.com/v1/oauth2/token" -X POST -d "response_type=token&grant_type=client_credentials"

(将上面的客户id和机密替换为您自己的)

确保付款$config模式是Sandbox,clientId和clientSecret密钥同时是Sandbox。

我也遇到了这个问题。我的Sandbox帐户上周工作正常,但现在突然不行了。如果你找到解决方案,请告诉我,我也会这样做!废话,我的问题最终是WordPress问题:我我们试图使用实时API,而不是沙盒API。这就是“凭据”“很明显,这意味着:API设置,而不是我最初怀疑的卡号。你也没有使用WordPress,是吗?我运行了cUrl测试,它确实返回了我的访问令牌。我从代码中复制并粘贴了凭据。我也使用了相同的沙盒端点。如果它不是我的凭证,也不是我的端点,那么它还能是什么?还有什么会使我的凭据无效?问题最终是SDK配置文件。我认为constants.php文件可以访问整个SDK中的凭据。我也向sdkconfig添加了凭据。我也收到了此错误。您是如何将凭据添加到sdkconfig的?我无法在项目中的任何位置找到此文件。
curl -v -u "client_id:secret" "https://api.sandbox.paypal.com/v1/oauth2/token" -X POST -d "response_type=token&grant_type=client_credentials"