How to get PayPal Access Token with cURL?

How to get PayPal Access Token with cURL?

Posted on:October 14, 2020 at 10:00 AM

Hey, if you are curious to know how to get PayPal access token with cURL, then this post might be helpful for you.

$ch = curl_init();
$clientId = "myclientid";
$secret = "mysecret";

curl_setopt($ch, CURLOPT_URL, "");  // For live, just use
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSLVERSION , 6);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $clientId.":".$secret);
curl_setopt($ch, CURLOPT_POSTFIELDS, "grant_type=client_credentials");

$result = curl_exec($ch);

if(empty($result))die("Error: No response.");
    $json = json_decode($result);


Hope it will be working for you.