0

This is PayPal's basic sandbox request to get an access token.

$curl = "curl -v https://api.sandbox.paypal.com/v1/oauth2/token
-H 'Accept: application/json' \
-H 'Accept-Language: en_US' \
-u 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp'
-d 'grant_type=client_credentials'";

This is what I've got so far as a conversion but it's failing.

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://api.sandbox.paypal.com/v1/oauth2/token");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Connection: Keep-Alive',
    'Accept-Language: en_US',
    'Accept: applictaion/json'
));
curl_setopt($ch, CURLOPT_USERPWD, 'EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, 'grant_type=client_credentials');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

print 'Running curl';

$res = curl_exec($ch);
echo $res;
curl_close($ch);
NateQ
  • 65
  • 6

1 Answers1

0

Try removing

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'Content-Type: application/x-www-form-urlencoded',
    'Connection: Keep-Alive',
    'Accept-Language: en_US',
    'Accept: applictaion/json'
));

I copied and pasted your code and just removed the CURLOPT_HTTPHEADER option and it worked!

Trevor
  • 31
  • 1
  • I don't know how you got it to work, I did what your saying and nothing prints to the screen – NateQ Jul 04 '14 at 16:44
  • Are you able to curl anything at all? It might be a problem with your curl extension. Also this might help you as well: http://stackoverflow.com/questions/15729167/paypal-api-with-php-and-curl?rq=1 – Trevor Jul 04 '14 at 18:00