0

I am trying fetch the access token by exchanging the code received from the URL and I have already configured the redirect uri and other configurations. The following is my callback.php:

$code = $_GET["code"];
$client_id = "";//actual client id
$client_secret = ""//actual client secret;
$redirect_uri = "http%3A%2F%2Flocalhost%2Ftest%2Fwebex_integration_test%2Fcallback.php";
$postRequest = array(
          "client_id" => ""//actual client id,
          "client_secret" => ""//actual client secret,
          "code" => $_GET["code"],
          "redirect_uri" => "http%3A%2F%2Flocalhost%2Ftest%2Fwebex_integration_test%2Fcallback.php",
          "code_verifier" => "abc"
        );
$cURLConnection = curl_init("https://api.webex.com/v1/oauth2/token?grant_type=authorization_code&client_id=$client_id&client_secret=$client_secret&code=$code&redirect_uri=$redirect_uri&code_verifier=abc");
      curl_setopt($cURLConnection, CURLOPT_POSTFIELDS, $postRequest);
      curl_setopt($cURLConnection, CURLOPT_RETURNTRANSFER, true);
      curl_setopt($cURLConnection, CURLOPT_HTTPHEADER, array(
                                          'Content-Type: application/x-www-form-urlencoded',
                                          'Connection: Keep-Alive'
                                          ));
$apiResponse = curl_exec($cURLConnection);
curl_close($cURLConnection);
$jsonArrayResponse = json_decode($apiResponse);
print_r($jsonArrayResponse); 

The above request results in a blank page. I am expecting the access token.

  • Do you have any errors (may be in the log file or you can enable them on the specific page)? Also check if there are any [curl errors](https://stackoverflow.com/questions/3987006/how-to-catch-curl-errors-in-php). – Nigel Ren Jul 19 '20 at 07:04
  • I am not receiving any status code, I have tested this request in POSTMAN and it works fine, but when I try through php its resulting in a blank page – Neeraj Malwal Jul 19 '20 at 07:06
  • A blank page could mean an error, it could mean no content. Have you tried adding an `echo` at the bottom of the code to see if it will at least get to the end of the script? – Nigel Ren Jul 19 '20 at 07:09
  • I just tried adding a print statement at the end of the script and its printing. – Neeraj Malwal Jul 19 '20 at 07:13
  • Try displaying the curl response - `echo $apiResponse;` as it could be that it's not JSON. – Nigel Ren Jul 19 '20 at 07:15
  • "Incorrect request parameters",Yes, that was the problem, I was expecting it be a JSON response. I will check the parameters once again but when I used the same parameters in POSTMAN it responded with a 200 status code. – Neeraj Malwal Jul 19 '20 at 07:19

1 Answers1

0

Try this class for PHP composer and don't waste the time

https://github.com/MoovFun/Xo-Curl

Truru
  • 1