【发布时间】:2020-11-14 02:43:56
【问题描述】:
在令牌 api 调用期间在沙盒凭据上使用 connect with paypal 时,我总是得到错误
Array ( [error] => invalid_client [error_description] => Client Authentication failed )
下面显示的是我正在使用的 CURL 调用。请帮帮我
$code = $_GET['code'];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=authorization_code&code=".$code."");
$headers = array();
$headers[] = 'Authorization: Basic client_id:client_secret';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$output = json_decode($result,true);
print_r($output);
【问题讨论】:
-
您的授权标头完全错误。要么阅读使用基本身份验证时实际应该如何发送用户名和密码 - 要么只设置
CURLOPT_USERPWD(如client_id:client_secret。)
标签: php curl paypal-sandbox