0

UPDATE If I perform a curl_error() this gets returned Protocol https not supported or disabled in libcurl

if I send a curl request via the command line I get an access token fine:

curl --data "code=removed&client_id=removed&client_secret=removed&redirect_uri=https://group.cs.cf.ac.uk/group3/oAuth2redirect.php&scope=https://www.googleapis.com/auth/calendar&grant_type=authorization_code" https://accounts.google.com/o/oauth2/token

However when I try and do this via php curl just returns nothing

$code = $_GET['code'];
$client_id = "removed";
$client_secret = "removed";
$redirectUri = "https://group.cs.cf.ac.uk/group3/oAuth2redirect.php";
$scope = "https://www.googleapis.com/auth/calendar";
$grant_type = "authorization_code";
$url = "https://accounts.google.com/o/oauth2/token/";

$params = array(
            'code' => $code,
            'client_id' => $client_id,
            'client_secret' => $client_secret,
            'redirect_uri' => $redirectUri,
            'scope' => $scope,
            'grant_type' => $grant_type
         );


$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params);
$response = curl_exec($ch);
curl_close($ch);

print_r($response);

does anyone know why this is happerning, I think it may to do with headers however I really can't work this out.

any help would be awesome

edit using Google's library for oauth2 is not an option

2 Answers 2

3

I've solved the problem now. It turns out curl was not set to be able do to ssl requests (as evident as curl_error() was returning Protocol https not supported or disabled in libcurl.

1
  • I know this is old but for answers like this it makes sense to explain how you corrected that issue, for other users; rather than just what it was. Commented Jul 24, 2018 at 15:20
2

I think ssl creating problem. Google is https, so it need set_opt("CURLOPT_SSL_VERIFYPEER",val) also, for more details visit, http://www.php.net/manual/en/function.curl-setopt-array.php beside other things, this may be problem.

2
  • I did already try this (I removed the options when it didn't work) however it still returns nothing
    – zidsal
    Commented Apr 30, 2013 at 17:37
  • I've just done a curl_error() on the code and I've been returned Protocol https not supported or disabled in libcurlbool(false
    – zidsal
    Commented Apr 30, 2013 at 17:41

Not the answer you're looking for? Browse other questions tagged or ask your own question.