Каждый раз, когда я пытаюсь получить информацию из подписки, я получаю сообщение об ошибке недостаточных прав доступа.
Я получаю токен из идентификатора клиента и секретного ключа той же учетной записи, которую я пытаюсь получить из информации,Это ответ следующего кода:
function getAccessToken($clientId, $secret)
{
$url = 'https://api.paypal.com/v1/oauth2/token';
$ch = curl_init();
$postData = [
'grant_type' => 'client_credentials',
];
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($postData));
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD, $clientId . ":" . $secret);
$headers = [];
$headers[] = "Accept: application/json";
$headers[] = "Accept-Language: en_US";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = json_decode(curl_exec($ch), true);
if (!isset($result['access_token'])) {
print_r($result);
return false;
}
print_r($result);
return $result['access_token'];
}
Ответ:
Array
(
[scope] => https://uri.paypal.com/services/invoicing https://uri.paypal.com/services/disputes/read-buyer https://uri.paypal.com/services/payments/realtimepayment https://uri.paypal.com/services/disputes/update-seller https://uri.paypal.com/services/paypalhere openid https://uri.paypal.com/services/payments/payment/authcapture https://uri.paypal.com/services/disputes/read-seller https://uri.paypal.com/services/payments/refund https://uri.paypal.com/services/identity/activities https://api.paypal.com/v1/vault/credit-card https://api.paypal.com/v1/payments/.* https://uri.paypal.com/services/reporting/search/read https://uri.paypal.com/payments/payouts https://api.paypal.com/v1/vault/credit-card/.* https://uri.paypal.com/services/applications/webhooks https://api.paypal.com/v1/payments/refund https://api.paypal.com/v1/payments/sale/.*/refund
[access_token] => XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[token_type] => Bearer
[app_id] => APP-XXXXXXXXXXXXXXxx
[expires_in] => 32400
[nonce] => 2019-06-27T09:09:XXXXXXXXXXXXXXXXXXXXXXXx
)
Вот как я пытаюсь получить информацию из подписки:
$url = 'https://api.paypal.com/v1/billing/subscriptions/I-XXXXXXX';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$headers = [];
$headers[] = "Accept: application/json";
$headers[] = "Authorization: Bearer $token";
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
print_r(json_decode(curl_exec($ch), true));
И это ответ:
Array
(
[name] => NOT_AUTHORIZED
[message] => Authorization failed due to insufficient permissions.
[debug_id] => 806a79b586a3b
[details] => Array
(
[0] => Array
(
[issue] => PERMISSION_DENIED
[description] => You do not have permission to access or perform operations on this resource.
)
)
[links] => Array
(
[0] => Array
(
[href] => https://developer.paypal.com/webapps/developer/docs/api/#FORBIDDEN
[rel] => information_link
[method] => GET
)
)
)
В разделе «Моя учетная запись» на панели инструментов разработчика у меня все включено для работы.
Есть идеи?