我试图使用授权码获取访问令牌,刷新令牌等。我正在使用以下代码,但会产生此错误:invalid Auth code
。我正在使用沙盒凭证来获取客户端ID和密钥ID。PayPal中的验证码错误
我从iOs设备收到$PaypalToken
。
那么问题是什么?
这是原来的贝宝要求:
curl ' https://api.paypal.com/v1/oauth2/token ' \
-H "Content-Type: application/x-www-form-urlencoded" \
-H "Authorization: Basic QWZV...==" \
-d 'grant_type=authorization_code&response_type=token& redirect_uri=urn:ietf:wg:oauth:2.0:oob&code=EBYhRW3ncivudQn8UopLp4A28...'
PHP Code:
$host2 = 'https://api.sandbox.paypal.com/v1/oauth2/token';
$clientId = 'XXXXXXX';
$clientSecret = 'xxxxxx';
$PaypalToken = $values->Token;
$postdata = 'grant_type=authorization_code&response_type=token&redirect_uri=urn:ietf:wg:oauth:2.0:oob&code='.$PaypalToken;
//$postdata = 'grant_type=client_credentials&response_type=token&code=wwwwwwwwwwwww';
//$postdata = 'grant_type=client_credentials';
$curl = curl_init($host2);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_USERPWD, $clientId.":".$clientSecret);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $postdata);
# curl_setopt($curl, CURLOPT_VERBOSE, TRUE);
$response = curl_exec($curl);
// Convert the result from JSON format to a PHP array
$json_response = json_decode($response,true);
if (empty($response)) {
curl_close($curl); // close cURL handler
$returnArr['Success'] = 0;
$returnArr['Message'] = $json_response['error_description'];
echo json_encode($returnArr);exit;
} else {
$info = curl_getinfo($curl);
//echo "<pre>";print_r($info);print_r($response);
curl_close($curl);
if($info['http_code'] != 200 && $info['http_code'] != 201) {
$returnArr['Success'] = 0;
$returnArr['Message'] = $json_response['error_description'];
echo json_encode($returnArr);exit;
}
}
echo "<pre>";print_r($json_response);
如果我改变$postdata = 'grant_type=client_credentials';
然后返回follwing:
Array ( [scope] => openid https://uri.paypal.com/services/invoicing https://api.paypal.com/v1/payments/ .* https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/vault/credit-card/ .*
[access_token] => A015KRoybqmm6eJqEzxX65jtGsd-L96g20KsAugrvSkB
[token_type] => Bearer
[app_id] => APP-80W284485P519543T
[expires_in] => 28800
)
那么如何让aceeess令牌,刷新令牌? 在此先感谢。
感谢您的回答。它是有益的。 – DS9 2014-10-08 14:22:05