我正在尝试使用 Zoom API 自动化登录过程,以允许我使用我的网站创建会议,但我似乎无法让登录工作,以便让我获得身份验证代码来调用 API 方法。我在 PHP 中执行此操作,而且我是新手,所以可能会犯一些基本错误。
如果我通过邮递员在下面的代码中进行 2 次调用并将代码从邮递员复制到我的 PHP,那么它可以工作一个小时(我的猜测是这是因为 cookie 有一个小时的有效期?)。鉴于我认为这取决于 cookie,我尝试了几种方法来复制 set-cookie 标头中返回的 cookie,但这仍然不起作用。有人可以帮我解决我所缺少的吗?如果代码混乱,请道歉...
<?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;
// ---------------------------------------------------------------
?>