无法从 Laravel 应用内向 Paypal Connect 发送 POST 请求
Can not send POST request to Paypal Connect from inside Laravel app
我有一个连接到 Paypal Connect 的应用程序。单击 Paypal 连接按钮后,我被带到 Paypal 网站,我确实收到了他们在验证后发送的代码。但是后来我无法将 POST 请求发送到带有 authorization_code 的 paypal 以要求我收到错误信息。我收到此错误:
由于身份验证凭据无效或缺少 ..
而且我很确定我的资历很好。
我错过了什么吗?
这是 Paypal 给我的:
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 发送 post 请求。请看下面的代码
$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);
查看 paypal api documentation,您的授权 header 似乎不正确。
Authorization request header:
The Base64-encoded client ID and secret credentials separated by a
colon (:). Use the partner's credentials.
您可以使用 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']
]
]
);
我有一个连接到 Paypal Connect 的应用程序。单击 Paypal 连接按钮后,我被带到 Paypal 网站,我确实收到了他们在验证后发送的代码。但是后来我无法将 POST 请求发送到带有 authorization_code 的 paypal 以要求我收到错误信息。我收到此错误: 由于身份验证凭据无效或缺少 .. 而且我很确定我的资历很好。 我错过了什么吗?
这是 Paypal 给我的:
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 发送 post 请求。请看下面的代码
$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);
查看 paypal api documentation,您的授权 header 似乎不正确。
Authorization request header: The Base64-encoded client ID and secret credentials separated by a colon (:). Use the partner's credentials.
您可以使用 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']
]
]
);