I am trying to automate the sign in process with the Zoom API to allow me to use my website to create meetings but I cannot seem to get the sign in to work in order to allow me to get an authentication code to call the API methods. I am doing this in PHP and I am fairly novice so may be making some fundamental errors.
If I make the 2 calls in the code below via postman and copy the code from postman to my PHP then it works for an hour (My guess is that this is because the cookies have an hour expiry?). Given I thought it was down to cookies I have tried a couple of way to copy the cookies returned in the set-cookie header but this still isn’t working. Can someone help me with what I am missing? Apologies if the code is messy…
<?php $curl = curl_init(); $headers = []; curl_setopt_array($curl, array( CURLOPT_URL => "https://zoom.us/oauth/v2/signin", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_HEADERFUNCTION => function($curl, $header) use (&$headers) { $len = strlen($header); $header = explode(':', $header, 2); if (count($header) < 2) // ignore invalid headers return $len; $headers[strtolower(trim($header[0]))][] = trim($header[1]); return $len; }, CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "POST", CURLOPT_POSTFIELDS => array('email' => 'some@thing.com','password' => 'somePassword','client_id' => 'someClientID','redirect_uri' => 'https://www.some.thing','response_type' => 'code','scope' => '','state' => ''), )); $response = curl_exec($curl); $cookie2 = "Cookie: "; echo "<br>_____<br>"; print_r($headers["set-cookie"]); echo "<br>_____<br>"; //echo var_dump(curl_getinfo($curl)); foreach ($headers["set-cookie"] as &$value) { echo "<br>------------<br>"; echo $value; $cookies = explode(';', $value); $cookie2 .= $cookies[0] . "; "; } unset($value); echo "<br>_____<br>"; echo $cookie2; echo "<br>_____<br>"; echo $response; $nextUrl = json_decode($response, true)["nextUrl"]; // ------------------------------------------- //$curl = curl_init(); curl_setopt_array($curl, array( CURLOPT_URL => "https://zoom.us/oauth/authorize?client_id=clientID&response_type=code&redirect_uri=https://www.some.thing", CURLOPT_RETURNTRANSFER => true, CURLOPT_ENCODING => "", CURLOPT_MAXREDIRS => 10, CURLOPT_TIMEOUT => 0, CURLOPT_FOLLOWLOCATION => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => "GET", CURLOPT_HTTPHEADER => array( $cookie2 ), )); $response = curl_exec($curl); curl_close($curl); $pieces = explode("> ", $response); $authCode = substr($pieces[1], 0, -3); echo "auth code: " . $authCode; // --------------------------------------------------------------- ?>
Advertisement
Answer
My Solution for this was to use a refresh token call instead to avoid the need for signing in for every call. Now for each call to the Zoom API I refresh the token and then make the API call, storing the tokens on the server for future use.