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.

Sign up to request clarification or add additional context in comments.

1 Comment

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.
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 Comments

I did already try this (I removed the options when it didn't work) however it still returns nothing
I've just done a curl_error() on the code and I've been returned Protocol https not supported or disabled in libcurlbool(false

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.