【发布时间】:2018-05-10 16:30:40
【问题描述】:
我正在开发一个使用 Paypal REST API 进行支付的在线商店。 在沙盒模式下一切正常,但当我尝试上线时,我收到了这条消息:
{"error":"invalid_client","error_description":"Client Authentication failed"}
我将身份验证 URL 更改为:https://api.paypal.com/v1/oauth2/token 我也将客户端 ID 和机密 ID 更改为实时 ID。
在仪表板中还有其他操作可以将我的帐户设置为实时模式吗?
我在我的代码中使用 curl。
protected $mode = 'PROD';
function getNewToken()
{
$url = "https://api.sandbox.paypal.com/v1/oauth2/token";
if ($this->mode == 'PROD')
$url = "https://api.paypal.com/v1/oauth2/token";
$token = new ModelAPIToken();
$token->set('app', 'test-paypal');
if ($this->mode == 'PROD')
$token->set('app', 'prod-paypal');
$token->select();
$data = 'grant_type=client_credentials';
$curlManager = new Curl();
$curlManager->setUrl($url);
$curlManager->addToHttpHeader('Accept-Language: en_US');
$curlManager->setCurlOpt(CURLOPT_USERPWD, $token->get('user_key') . ":" . $token->get('user_secret'));
$curlManager->execute($data);
$response = $curlManager->getResponse();
preg_match('#"access_token":"(.*)","token_type"#', $response, $match);
$access_token = $match[1];
$token->set('access_token', $access_token);
$token->save();
}
【问题讨论】:
-
您是否在开发者仪表板/您的应用上启用了实时环境?登录您的开发者帐户并点击“我的应用和凭据”,然后点击“实时”按钮。
-
有“直播”按钮,但无法点击。我试过 Safari 和 Chrome。
-
联系您的贝宝支持。我认为您的帐户尚未激活!!
-
我是几个小时前做的。暂时没有答案。
标签: php api curl paypal paypal-sandbox