How to get PayPal Access Token with cURL?

2 years ago

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.

Thouhedu Islam Suchi

Thouhedul Islam

Laravel Developer

Hi, I am a Laravel Developer with a passion for web development. I specialize in PHP, particularly Laravel, as well as Javascript, MySql, and other cutting-edge web technologies.

During the day, I work for GLEIF, where I apply my skills and experience to develop innovative web applications. At night, I enjoy contributing to the community and solving problems. You can often find me on Laracasts, where I love to stay active and keep up-to-date with the latest trends in web development.

I am excited about the potential of technology and its power to transform people's lives.