Php 贝宝-订阅-创建产品

Php 贝宝-订阅-创建产品,php,curl,paypal,paypal-sandbox,paypal-subscriptions,Php,Curl,Paypal,Paypal Sandbox,Paypal Subscriptions,我正在尝试与paypal进行订阅集成。 我按照这里的指示: 我在第2步(创建产品)中遇到问题。 我正在使用php进行curl调用,但我遇到了错误,无法解决它。卷曲链接是: 我得到的答复是: { "name": "NOT_AUTHORIZED", "message": "Authorization failed due to insufficient permissions.", "debug_id": "7de3b61dcde85", "details": [

我正在尝试与paypal进行订阅集成。 我按照这里的指示:

我在第2步(创建产品)中遇到问题。 我正在使用php进行curl调用,但我遇到了错误,无法解决它。卷曲链接是:

我得到的答复是:

{
    "name": "NOT_AUTHORIZED",
    "message": "Authorization failed due to insufficient permissions.",
    "debug_id": "7de3b61dcde85",
    "details": [
        {
            "issue": "PERMISSION_DENIED",
            "description": "You do not have permission to access or perform operations on this resource"
        }
    ],
    "links": [
        {
            "href": "https://developer.paypal.com/docs/api/v1/billing/subscriptions#NOT_AUTHORIZED",
            "rel": "information_link",
            "method": "GET"
        }
    ]
}

有人知道我该怎么修吗?如何添加权限以便创建产品?

首先,您必须访问令牌才能授权权限

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/oauth2/token');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_USERPWD,  'your client id' .':'. 'your secret Key');
$headers = array();
$headers[] = 'Accept: application/json';
$headers[] = 'Accept-Language: en_US';
$headers[] = 'Content-Type: application/x-www-form-urlencoded';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);

$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$accessToken json_decode($result);
获得访问令牌后,您将发送另一个点击来创建产品

$ch = curl_init();curl_setopt($ch, CURLOPT_URL, 'https://api.sandbox.paypal.com/v1/catalogs/products');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"name": "Test Recurring","type": "SERVICE}');
curl_setopt($ch, CURLOPT_POST, 1);
$headers = array();
$headers[] = 'Content-Type: application/json';
$headers[] = 'Authorization: '.$accessToken->token_type.' '.$accessToken->access_token.'';
$headers[] = 'Paypal-Request-Id: <your client id>';
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
if (curl_errno($ch)) {
    echo 'Error:' . curl_error($ch);
}
curl_close($ch);
$createProduct = json_decode($result);
$ch=curl_init();curl_setopt($ch,CURLOPT_URL,'https://api.sandbox.paypal.com/v1/catalogs/products');
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,{“name”:“Test recurtive”,“type”:“SERVICE}”);
卷曲设置($ch,卷曲设置桩,1);
$headers=array();
$headers[]=“内容类型:application/json”;
$headers[]=“授权:”.$accessToken->token_-type.“.$accessToken->access_-token.”;
$headers[]=“贝宝请求Id:”;
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
$result=curl\u exec($ch);
if(旋度误差($ch)){
echo“Error:”.curl_Error($ch);
}
卷曲关闭($ch);
$createProduct=json_decode($result);
在这里,您的产品创建已完成,您将获得一个产品id

参考文献1:


参考2:

这不起作用。我认为$accessToken是一个字符串,因此$accessToken->token\u type不返回任何内容。产品不是在这里创建的。