贝宝:授权由于权限不足而失败

时间:2019-06-27 09:39:42

标签: php paypal paypal-subscriptions

每次尝试从订阅获取信息时,都会出现权限不足错误。

我从试图获取信息的同一帐户的客户端ID和密码中获取令牌。 这是以下代码的响应:

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
                )

        )

)

在开发人员信息中心的“我的帐户”部分中,我已启用所有功能。

有什么主意吗?

0 个答案:

没有答案