我正在尝试向 Zoom API 发出一个简单的 API 请求 - 将注册者插入网络研讨会。 据我所知,我需要获取 OAuth 密钥,然后进行第二次调用以将注册者插入网络研讨会。 我收到一个错误:
“OAuth 请求失败:400 {“reason”:“不支持的授权类型”,“error”:“unsupported_grant_type”}”
这里有一个可以帮助您的解释:
https://developers.zoom.us/docs/internal-apps/s2s-oauth/
这是我的代码(我隐藏了 API 密钥、密钥和帐户 ID):
class Zoom_Api
{
public function getToken() {
$url = 'https://zoom.us/oauth/token';
$data = array(
'grant_type' => 'account_credentials',
'account_id' => '*******'
);
$zoomAPIKey = '************';
$zoomSecretKey = '************';
$headers = array(
'Authorization: Basic '. base64_encode($zoomAPIKey.":".$zoomSecretKey)
);
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($curl);
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($httpCode == 200) {
// Parse the JSON response to get the access token
$oauthResponse = json_decode($response, true);
$accessToken = $oauthResponse['access_token'];
return $accessToken;
} else {
echo 'OAuth Request Failed: ' . $httpCode . PHP_EOL;
echo $response . PHP_EOL;
return null;
}
curl_close($curl);
}
public function sentRequest() {
$name = "testdfdf";
$email = "[email protected]";
$webinarID = 867098960000;
$regData = array(
'email' => $email,
'first_name' => $name,
);
$jsonStrReg = json_encode($regData);
$httpStrReg = http_build_query($regData);
$ch = curl_init('https://api.zoom.us/v2/webinars/'.$webinarID.'/registrants');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $httpStrReg);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $this->getToken()
));
$response = curl_exec($ch);
$response = json_decode($response);
curl_close($ch);
return $response;
}
}
$zoom_meeting = new Zoom_Api();
$response = $zoom_meeting->getToken();
echo "<pre>";
print_r($response);
echo "<pre>";
有什么问题吗?
我发现了问题:我在 Zoom 上创建了错误的应用程序类型,并且第二个请求中缺少请求数据类型。