我有一个连接到Paypal Connect的应用程序。单击贝宝连接按钮后,我将被带到贝宝网站,并且我确实收到了验证后发送的代码。但是,然后我无法使用authorization_code将POST请求发送到贝宝以要求用户信息,我收到错误。我收到此错误: 由于身份验证凭据无效或丢失,导致身份验证失败。 而且我很确定自己的资历很好。 我想念什么吗?
这是贝宝给我的:
curl -X POST https://api.sandbox.paypal.com/v1/oauth2/token \
-H 'Authorization: Basic {Your Base64-encoded ClientID:Secret}=' \
-d 'grant_type=refresh_token&refresh_token={refresh token}'
我正在使用Guzzle发送发帖请求。请参见下面的代码
$client = new \GuzzleHttp\Client();
$headers = [
'Authorization' => 'Basic clientID:clientSecret'
];
$response = $client->request('POST',
'https://api.sandbox.paypal.com/v1/oauth2/token',
[
'grant_type ' => 'authorization_code',
'code' => $data['code']
],
$headers);
答案 0 :(得分:2)
看着paypal api documentation,似乎您的授权标头不正确。
授权请求标头: Base64编码的客户端ID和秘密凭证,以 冒号(:)。使用合作伙伴的凭据。
您可以使用php的base64_encode()函数执行此操作。
$client = new \GuzzleHttp\Client();
$authorizationString = base64_encode($clientId . ':' . $clientSecret);
$client->request(
'POST',
'https://api.sandbox.paypal.com/v1/oauth2/token',
[
'headers' => [
'Authorization' => 'Basic ' . $authorizationString
],
'form_params' => [
'grant_type ' => 'authorization_code',
'code' => $data['code']
]
]
);